开发者

Google Maps API v3 calculate distance ,duration Synchronously

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜