在Google Map API V3中使用Transit作为我的旅行模式



当我在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);
  }
});

}

是的,https://developers.google.com/maps/documentation/javascript/directions#transitoptions

"在旅行模式之间,指示请求的可用选项会有所不同。在请求运输方向时,避开路线,避免通道,路点,路点[]和OptimizeWaypoints选项将被忽略。您可以通过TransitoPtions Object Object Object Object Object Object object object。

如果要使用它,则必须拆分请求。

当TravelMode运输时,您无法指定航路点。

文档(现在)指出:

不支持过境方向的航路点。

指示服务在这种情况下总是返回Invalid_request。

示例

最新更新