0
votes

For example I have 5 location with lat and lng. My requirement is I need to get the best route among these location along with current location

https://maps.googleapis.com/maps/api/directions/json?origin=lat,lng&destination=lat,lng&mode=driving&sensor=false&alternatives=true&waypoints=[]

The above API may get source to destination best route but not the best way among the 5 locations

For example Currently I am at Washington, I have to visit New York, Chicago, Massachusetts, Portland and Boston. In which order I can visit these places, so that travelling distance should me minimal.

1
I guess to achieve this we need to have our own logic by using the above API requestSHASHANK

1 Answers

0
votes

To get the best route you need to add optimize:true in the waypoints.

Here is an example from the documentation:

https://maps.googleapis.com/maps/api/directions/json?origin=Adelaide,SA&destination=Adelaide,SA&waypoints=optimize:true|Barossa+Valley,SA|Clare,SA|Connawarra,SA|McLaren+Vale,SA&key=YOUR_API_KEY