Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Maps API V3 - How to Get Optimal Roundtrip Route Through Arbitrary Waypoints

There are many questions regarding Google Maps V3 API waypoints but none that address how to get optimal round trip route from a set of arbitrary waypoints. Basically, the order of weighpoints should be determined by whatever is the most optimum path and is not necessarily dictated by the order fed into the system. Does anybody know if this is even possible?

like image 317
VinnyD Avatar asked Apr 27 '12 23:04

VinnyD


1 Answers

There is an "optimize" option in the V3 API. Have you tried it?

optimizeWaypoints

If set to true, the DirectionService will attempt to re-order the supplied 
intermediate waypoints to minimize overall cost of the route. If waypoints 
are optimized, inspect DirectionsRoute.waypoint_order in the response to 
determine the new ordering.

optimizeWaypoints (optional) specifies that the route using the supplied 
waypoints may be optimized to provide the shortest possible route.

First paragraph from https://developers.google.com/maps/documentation/javascript/reference.

Second from https://developers.google.com/maps/documentation/javascript/directions

like image 178
Tina CG Hoehr Avatar answered Oct 11 '22 23:10

Tina CG Hoehr