google地圖的路線實(shí)現(xiàn)代碼
<script language="javascript" type="text/javascript">
//add by ahuinan 2009-8-17
//initialize(23.165613663312594,113.35968017578125)
var map;
var gdir;
var marker2;
var hasMarker = false;
var hotelLatLng = new GLatLng(<%=initxy %>);//初始化酒店的坐標(biāo)
var polyline;
var points = [];
points[1] = hotelLatLng;
function initialize() {
if (GBrowserIsCompatible()) {
map = new GMap2(document.getElementById("divMap"), { googleBarOptions: { showOnLoad: true} });
gdir = new GDirections(map);
map.setCenter(hotelLatLng, 9);
map.addControl(new GOverviewMapControl());
map.addControl(new GLargeMapControl());
//加入搜索框
map.enableGoogleBar();
map.enableScrollWheelZoom();
//創(chuàng)建酒店的標(biāo)注,不可拖動(dòng)
var hotelMarker = new GMarker(new GLatLng(<%=initxy %>));
map.addOverlay(hotelMarker);
//鼠標(biāo)左鍵可以建立一個(gè)標(biāo)記,
GEvent.addListener(map,"click",function(overlay,latlng,overlaylatlng){
if(latlng == null || hasMarker == true){
return;
}
var greenIcon = new GIcon(G_DEFAULT_ICON);
greenIcon.image = "../googlemap/green-dot.png";
greenIcon.iconSize = new GSize(32,32);
greenIcon.iconAnchor = new GPoint(16,32);
greenIcon.shadowSize=new GSize(56,33);
marker2 = new GMarker(latlng,{draggable: true,icon:greenIcon});
map.addOverlay(marker2);
GEvent.addListener(marker2,"dragend",function(){
points[0] = marker2.getLatLng();
gdir.loadFromWaypoints(points,{"preserveViewport":true});
})
GEvent.addListener(gdir, "addoverlay", function(){
for (var i=0; i<=gdir.getNumRoutes(); i++){
var originalMarker = gdir.getMarker(i);
map.removeOverlay(originalMarker);
}
polyline = gdir.getPolyline();
polyline.setStrokeStyle({color:"red",weight:2,opacity:1});
// map.addOverlay(polyline);
});
hasMarker = true;
points[0] = latlng;
gdir.loadFromWaypoints(points,{"preserveViewport":true});
})
}
}
//按下添加按鈕
function add(){
if(points.length == 1){
alert("沒(méi)有線路,終止操作");
}else{
window.opener.document.getElementById("txtHI_MapMarkDesc").value = window.opener.document.getElementById("txtHI_MapMarkDesc").value+"\n"+document.getElementById("txtName").value+"||||"+document.getElementById("txtType").value+"||||"+points[0]+"\n";
window.close();
}
}
window.onload = function() {
initialize()
}
</script>
- Google 地圖類(lèi)型詳解及示例代碼
- Google 地圖控件集詳解及實(shí)例代碼
- Google 地圖事件實(shí)例講解
- Google 地圖疊加層實(shí)例講解
- Google 地圖獲取API Key詳細(xì)教程
- 百度地圖經(jīng)緯度轉(zhuǎn)換到騰訊地圖/Google 對(duì)應(yīng)的經(jīng)緯度
- php使用google地圖應(yīng)用實(shí)例
- Google Maps API地圖應(yīng)用示例分享
- Google 靜態(tài)地圖API實(shí)現(xiàn)代碼
- 為IP查詢(xún)添加GOOGLE地圖功能的代碼
- Google 地圖API資料整理及詳細(xì)介紹
相關(guān)文章
bootstrap導(dǎo)航條實(shí)現(xiàn)代碼
這篇文章主要為大家詳細(xì)介紹了bootstrap導(dǎo)航條的實(shí)現(xiàn)代碼,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-12-12JavaScript實(shí)現(xiàn)捕獲鼠標(biāo)坐標(biāo)
這篇文章主要為大家詳細(xì)介紹了JavaScript實(shí)現(xiàn)捕獲鼠標(biāo)坐標(biāo),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-04-04JS實(shí)現(xiàn)對(duì)JSON數(shù)據(jù)進(jìn)行冒泡排序
JavaScript 是一種廣泛使用的腳本語(yǔ)言,JSON是一種常見(jiàn)的數(shù)據(jù)格式,這篇文章主要來(lái)探討一下如何使用 JavaScript 對(duì) JSON 數(shù)據(jù)進(jìn)行冒泡排序,感興趣的可以了解一下2023-06-06微信小程序開(kāi)發(fā)之錄音機(jī) 音頻播放 動(dòng)畫(huà)實(shí)例 (真機(jī)可用)
這篇文章主要介紹了微信小程序開(kāi)發(fā)之錄音機(jī) 音頻播放 動(dòng)畫(huà)實(shí)例 (真機(jī)可用),這里整理了詳細(xì)的代碼,有需要的小伙伴可以參考下。2016-12-12原生JS實(shí)現(xiàn)非常好看的計(jì)數(shù)器
這篇文章主要為大家詳細(xì)介紹了原生JS實(shí)現(xiàn)非常好看的計(jì)數(shù)器,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-10-10d3.js實(shí)現(xiàn)自定義多y軸折線圖的示例代碼
本篇文章主要介紹了d3.js實(shí)現(xiàn)自定義多y軸折線圖的示例代碼,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-05-05前端報(bào)錯(cuò)Failed?to?resolve?component:?smile-outlined?If?thi
這篇文章主要為大家介紹了前端報(bào)錯(cuò)?Failed?to?resolve?component:?smile-outlined?If?this?is?a?native?custom?的問(wèn)題分析解決,有需要的朋友可以借鑒參考下2023-06-06深入淺出JavaScript前端中的設(shè)計(jì)模式
這篇文章主要介紹了JavaScript前端中的設(shè)計(jì)模式,設(shè)計(jì)模式是一套被反復(fù)使用,多數(shù)人知曉的,經(jīng)過(guò)分類(lèi)編目的,代碼設(shè)計(jì)經(jīng)驗(yàn)的總結(jié),感興趣想要詳細(xì)了解可以參考下文2023-05-05一些常用的JavaScript函數(shù)(json)附詳細(xì)說(shuō)明
一些常用的JavaScript函數(shù)(json)附詳細(xì)說(shuō)明,學(xué)習(xí)js的朋友可以參考下。2011-05-05