Reputation: 45
Calculating distance between two point with google maps is easy and I did. But how to calculate distance between more then two marks in google map with the help of google maps api?
Upvotes: 0
Views: 8666
Reputation: 4037
This is quite a broad use-case, But for a simple solution of your question I would recommend you using a Distance Matrix API. This would help you to find distances in between two or even more cities. The API request to find the distance in between 4 cities would be like this.
https://maps.googleapis.com/maps/api/distancematrix/json?origins=Vancouver+BC|Seattle&destinations=San+Francisco|Victoria+BC&mode=bicycling&language=fr-FR&key=API_KEY
This request will return four elements - two origins times two destinations:
Vancouver to San Francisco, Vancouver to Victoria, Seattle to San Francisco & Seattle to Victoria
Please take a look at the official Google Documentation of Distance Matrix API to know more about the API requests for more origins and destination.
One more option for you is to use a Direction API, but that would cover points in a path and there respective distance.
Hope that Helps!!
Upvotes: 2