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
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.
The Distance Matrix API uses a pay-as-you-go pricing model.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With