2012-10-27 51 views
1

當我在Google Map API中使用TRANSIT作爲我的旅行模式時,我在DirectionsRequest中定義了出發地,目的地和一些路標。然而,當DirectionsResult返回時,DirectionsLeg僅從我的出發開始並以我的目的地結束,它跳過了我所有的路標。 我的代碼如下所示 有沒有人在這裏得到同樣的問題?在Google Map API中使用TRANSIT作爲我的旅行模式

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); 
    } 
}); 

}

+0

您能否提供展示問題的示例開始,結束和航點? – geocodezip

+0

也是您正在使用的TransitOptions。 – geocodezip

回答

相關問題