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?
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
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