Chris
Chris

Reputation: 1

Google Maps API v3 calculate distance ,duration Synchronously

Is there any way to calculate distance and 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).

Upvotes: 0

Views: 962

Answers (1)

Linus Kleen
Linus Kleen

Reputation: 34652

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 

Upvotes: 1

Related Questions