Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google MAP API v3: computeDistanceBetween method and distance in metric form

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

I didn't understand what computeDistanceBetween method returns in units.

Thanks

like image 756
Hellnar Avatar asked Jul 06 '11 18:07

Hellnar


People also ask

Can Google Maps API calculate distance between two points?

The API returns information based on the recommended route between start and end points. You can request distance data for different travel modes, request distance data in different units such kilometers or miles, and estimate travel time in traffic.

Is Google Distance Matrix API free?

The Distance Matrix API uses a pay-as-you-go pricing model.

What is Google Distance Matrix API?

Also see the Maps JavaScript API Reference: Distance Matrix. Google's Distance Matrix service computes travel distance and journey duration between multiple origins and destinations using a given mode of travel. This service does not return detailed route information.


1 Answers

It's in meters. To convert to kilometers divide by 10241000, obviously.

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

By the way, the underlying code of this library method is based on the Haversine formula.

like image 158
katspaugh Avatar answered Oct 23 '22 22:10

katspaugh