【发布时间】:2023-03-31 00:37:01
【问题描述】:
大家好,我正在开发一个跟踪系统,我必须使用谷歌地图的 API 来计算 ETA(预计到达时间)。 我有行车距离。 但是我需要到到达点的公里数才能预测到达时间。
下面的行驶距离值怎么称呼?
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));
【问题讨论】: