API MAP API v3: computeDistanceBetween method and metric distance

I want to calculate the direct distance between positions in metric form. (i.e. from A to B in kilometers).

I did not understand that the computeDistanceBetween method returns in units.

thanks

+8
javascript google-maps-api-3
source share
1 answer

It is in meters. To convert to kilometers, divide by 1024 1000, obviously .

google.maps.geometry.spherical.computeDistanceBetween( Moscow, Leningrad ); // 679601 m 

By the way, the base code for this library method is based on the Haversin formula .

+18
source share

All Articles