开发者

Google Maps API v3 calculate distance ,duration Synchronously

开发者 https://www.devze.com 2023-01-30 06:01 出处:网络
Is there any way to calculate distance an开发者_Python百科d duration in google maps v3 synchronously? I want to make a function which will take 2 parameter (latLng, latLng) and return the distance (no

Is there any way to calculate distance an开发者_Python百科d duration in google maps v3 synchronously? 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).


You don't need Google. You need the Haversine formula:

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 
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号