[英]Google Maps API v3 calculate distance ,duration Synchronously
Is there any way to calculate distance and duration in google maps v3 synchronously ? 有什么方法可以同步计算google maps v3中的距离和持续时间吗? I want to make a function which will take 2 parameter (latLng, latLng) and return the distance (not in straight line but through roads) between them (or the duration).
我想制作一个函数,该函数将使用2个参数(latLng,latLng)并返回它们之间的距离(或持续时间)(不是直线,而是通过道路)。
You don't need Google. 您不需要Google。 You need the Haversine formula :
您需要Haversine公式 :
R = earth’s radius (mean radius = 6,371km)
Δlat = lat2 − lat1
Δlong = long2 − long1
a = sin²(Δlat/2) + cos(lat1) * cos(lat2) * sin²(Δlong/2)
c = 2 * atan2(√a, √(1−a))
d = R * c
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.