如何更正谷歌地图上的标记

时间:2016-02-16 15:36:17

标签: javascript html google-maps google-maps-api-3

如何更正附加图像中的标记(Alphabates),因为此标记给出了错误的指针Alphabates名称请参见图像,

enter image description here

我有这个HTML:

  <!DOCTYPE html><html><head><meta http-equiv="X-UA-Compatible" content="IE=edge">   <meta http-equiv="content-type" content="text/html; charset=UTF-8"/> <title>Google Maps Directions Waypoints</title>    <link href="http://code.google.com/apis/maps/documentation/javascript/examples/default.css" rel="stylesheet" type="text/css" />    <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false">   </script>  <script type="text/javascript"> var directionDisplay;    var directionsService = new google.maps.DirectionsService();  var map;       function initialize() {    directionsDisplay = new google.maps.DirectionsRenderer({  });  var myOptions = {   zoom: 10, mapTypeId: google.maps.MapTypeId.ROADMAP, } ; map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);  directionsDisplay.setMap(map); calcRoute(); } function calcRoute() { var waypts = [];  
  stop = new google.maps.LatLng(51.126232,0.265945) ; 
  waypts.push({location:stop,  stopover:true}); 

  stop = new google.maps.LatLng(51.593165,-0.028696) ; 
  waypts.push({location:stop,  stopover:true});  
  stop = new google.maps.LatLng(51.488874,-0.287175) ; 
  waypts.push({location:stop,  stopover:true});  
  stop = new google.maps.LatLng(51.440487,-0.155701) ;
  waypts.push({location:stop,  stopover:true}); 

  start  = new google.maps.LatLng(51.126232,0.265945);
  end = new google.maps.LatLng(51.593165,-0.028696);


  var request = {  origin: start,  destination: end, 
  waypoints: waypts,  optimizeWaypoints: true, 
  travelMode: google.maps.DirectionsTravelMode.WALKING };
  directionsService.route(request, function(response, status)
  {  if (status == google.maps.DirectionsStatus.OK)
  {    directionsDisplay.setDirections(response);  
  var route = response.routes[0]; }     });   }  
  </script> 
  </head>
  <body onLoad="initialize()"> <div id="map_canvas" style="width:70%;height:80%;"></div>  </body></html>

1 个答案:

答案 0 :(得分:0)

看起来你的起点和第一个航路点是完全相同的点,所以碰巧B显示在A的顶部。

stop = new google.maps.LatLng(51.126232,0.265945) ; // SAME AS START
waypts.push({location:stop,  stopover:true}); 

stop = new google.maps.LatLng(51.593165,-0.028696) ; // SAME AS END
waypts.push({location:stop,  stopover:true});  
stop = new google.maps.LatLng(51.488874,-0.287175) ; 
waypts.push({location:stop,  stopover:true});  
stop = new google.maps.LatLng(51.440487,-0.155701) ;
waypts.push({location:stop,  stopover:true}); 

start  = new google.maps.LatLng(51.126232,0.265945); // SAME AS FIRST WAYPOINT
end = new google.maps.LatLng(51.593165,-0.028696); // SAME AS SECOND WAYPOINT

删除第一个航路点,它们应从A开始。

对于缺少的E,您有一个名为 optimizeWaypoints 的选项设置为true。引自https://developers.google.com/maps/documentation/javascript/directions

  

optimizeWaypoints(可选)指定可以优化使用提供的航点的路线以提供尽可能短的路线。如果为true,则Directions服务将在waypoint_order字段中返回重新排序的航点。

这导致第二个航路点被重新排序为实际上在结束之前的最后一个,并且因为它们在彼此之上,与在开始时相同,后一点仅被显示,并且字母E是你的地图上遗漏了。

相关问题