google地图的路线实现代码
更新时间:2009年08月20日 01:18:40 作者:
google地图的路线实现代码,大家可以参考下,实现自己想要的功能。
复制代码 代码如下:
<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 %>);//初始化酒店的坐标
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();
//创建酒店的标注,不可拖动
var hotelMarker = new GMarker(new GLatLng(<%=initxy %>));
map.addOverlay(hotelMarker);
//鼠标左键可以建立一个标记,
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("没有线路,终止操作");
}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>
相关文章
前端报错Failed to resolve component: smile-outlined If thi
这篇文章主要为大家介绍了前端报错 Failed to resolve component: smile-outlined If this is a native custom 的问题分析解决,有需要的朋友可以借鉴参考下2023-06-06
最新评论