구글 지도의 노선 구현 코드

3249 단어
 
  
<br>//add by ahuinan 2009-8-17 <br>//initialize(23.165613663312594,113.35968017578125) <br>var map; <br>var gdir; <br>var marker2; <br>var hasMarker = false; <br>var hotelLatLng = new GLatLng(<%=initxy %>);// <br>var polyline; <br>var points = []; <br>points[1] = hotelLatLng; <br>function initialize() { <br>if (GBrowserIsCompatible()) { <br>map = new GMap2(document.getElementById("divMap"), { googleBarOptions: { showOnLoad: true} }); <br>gdir = new GDirections(map); <br>map.setCenter(hotelLatLng, 9); <br>map.addControl(new GOverviewMapControl()); <br>map.addControl(new GLargeMapControl()); <br> <br>// <br>map.enableGoogleBar(); <br> <br>map.enableScrollWheelZoom(); <br> <br>// , <br>var hotelMarker = new GMarker(new GLatLng(<%=initxy %>)); <br>map.addOverlay(hotelMarker); <br> <br>// , <br>GEvent.addListener(map,"click",function(overlay,latlng,overlaylatlng){ <br>if(latlng == null || hasMarker == true){ <br>return; <br>} <br>var greenIcon = new GIcon(G_DEFAULT_ICON); <br>greenIcon.image = "../googlemap/green-dot.png"; <br>greenIcon.iconSize = new GSize(32,32); <br>greenIcon.iconAnchor = new GPoint(16,32); <br>greenIcon.shadowSize=new GSize(56,33); <br>marker2 = new GMarker(latlng,{draggable: true,icon:greenIcon}); <br>map.addOverlay(marker2); <br> <br>GEvent.addListener(marker2,"dragend",function(){ <br>points[0] = marker2.getLatLng(); <br>gdir.loadFromWaypoints(points,{"preserveViewport":true}); <br> <br> <br> <br>}) <br>GEvent.addListener(gdir, "addoverlay", function(){ <br>for (var i=0; i<=gdir.getNumRoutes(); i++){ <br>var originalMarker = gdir.getMarker(i); <br>map.removeOverlay(originalMarker); <br>} <br>polyline = gdir.getPolyline(); <br> <br> <br>polyline.setStrokeStyle({color:"red",weight:2,opacity:1}); <br>// map.addOverlay(polyline); <br> <br>}); <br>hasMarker = true; <br>points[0] = latlng; <br>gdir.loadFromWaypoints(points,{"preserveViewport":true}); <br> <br>}) <br>} <br>} <br>// <br>function add(){ <br>if(points.length == 1){ <br>alert(" , "); <br>}else{ <br>window.opener.document.getElementById("txtHI_MapMarkDesc").value = window.opener.document.getElementById("txtHI_MapMarkDesc").value+"
"+document.getElementById("txtName").value+"||||"+document.getElementById("txtType").value+"||||"+points[0]+"
"; <br>window.close(); <br>} <br>} <br>window.onload = function() { <br>initialize() <br>} <br>

좋은 웹페이지 즐겨찾기