0
嘿,我正在開發一個跟蹤系統,我必須使用谷歌地圖的API來計算ETA(預計到達時間)。 我有駕駛距離。 但我需要到達目的地的公里以便能夠預測到達時間。JavaScript-谷歌地圖API
我該如何稱下面的行車距離值?
directionsService.route(request,
function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
(response.routes[0].legs[0].distance.value); // the distance in metres
return((response.routes[0].legs[0].distance.value)/1000); //distance e kilometres
}
else {
// oops, there's no route between these two locations
// every time this happens, a kitten dies
// so please, ensure your address is formatted properly
}
});
function getArrivalTime(distance, vel) {
return distance/vel;
};
console.log(getArrivalTime(distance,vel));