当我在 Google Map api V3 中使用 TRANSIT 作为我的旅行模式时,我在 DirectionsRequest 中定义了起点、目的地和一些航点。但是,当 DirectionsResult 回来时,DirectionsLeg 仅以我的起点开始并以我的目的地结束,它跳过了我所有的航路点。我的代码如下所示有人在这里遇到同样的问题吗?
function calcRoute(waypts, mode) {
var sites = [];
var mode;
//Add waypoints to array, the first and last one are not added in waypoints
for (var i = 1; i < waypts.length-2; i++) {
sites.push({
location:waypts[i],
stopover:true}); //Set true to show that stop is required
}
var request = {
origin: waypts[0], //Set the first one as origin
destination:waypts[waypts.length-1],//Set the last one as destination
waypoints:sites,//Set waypoints
optimizeWaypoints:false,
travelMode: google.maps.TravelMode[mode]
};
//Send to Google
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
var route = response.routes[0];
var HTMLContent = "";
//Get response and show on my HTML
for(var i =0; i < route.legs.length; i++){
HTMLContent = "From " + route.legs[i].start_address + "To " + route.legs[i].end_address + "<br>";
HTMLContent = HTMLContent + "Distance:" + route.legs[i].distance.text + "<br>";
}
$("#route_Scroll").append(HTMLContent);
}else{
alert(status);
}
});
}