xkjyeah / vue-google-maps

Google maps component for vue with 2-way data binding
https://xkjyeah.github.io/vue-google-maps/
1.88k stars 473 forks source link

Distance calculation #273

Open Michael-Reich opened 6 years ago

Michael-Reich commented 6 years ago

Is there any exmaple of how to calculate the distance from markers around the center to the center?

Do you have any code snippet or example, that would be super great!

gepd commented 6 years ago

The google documentation says you need the DistanceMatrixService object to do what you want, and I don't see any reference on the API to that object, so I guess you can't at this moment with this package.

There is another way with an HTTP request: https://developers.google.com/maps/documentation/distance-matrix/start you can pass the latlng as is explained here

oppianmatt commented 6 years ago

The DistanceMatrixService is for travel distance. But if you just want to know the distance between 2 points you can use a formula to work it out. Most common one is the Haversine formula for calculating the distance between 2 points on a sphere.

https://en.wikipedia.org/wiki/Haversine_formula

Here is a page that describes how to do it in javascript.

http://www.movable-type.co.uk/scripts/latlong.html