2017-02-20 66 views

回答

0

使用方向服務的計算方法對於駕駛,步行,騎車是相同的。這裏有一個基本的例子:

directionsService.route(request, function(result, status) { 
if (status == google.maps.DirectionsStatus.OK) { 
    path = result.routes[0].overview_path; 
    var sumKM = 0; 
    var myroute = result.routes[0]; 
    for (var i = 0; i < myroute.legs.length; i++) { 
     sumKM += myroute.legs[i].distance.value; //legs = Abschnitte from point to point 
    } 
    sumKM = sumKM/1000; 
    //console.log("Route calculated, write the route") 
    //writeRoute(path, sumKM, index) 
} else if (status == google.maps.DirectionsStatus.ZERO_RESULTS) { 
    alert("Could not find a route between these points"); 
} else { 
    alert("Directions request failed! Reset Marker!"); 
} 
});