Is there a way using the Google Maps API to get back an "optimized" route given a set of waypoints (in other words, a "good-enough" solution to the traveling salesman problem), or does it always return the route with the points in the specified order?
Google Maps actually has zero route optimization features, meaning you have to do all the calculations manually when you have multiple stops to make.
If you want to find the fastest route, you must manually reorder the stops until you see the shortest estimated time. To adjust the order, drag the three lines on the right-hand side of each stop and drop it in a different place. Then, compare the estimated time of arrival (ETA) of different routes.
You can draw a route on Google Maps that includes a driving, walking, or cycling route and save it or share it with others. To create a route, open "Your places" in the menu on Google Maps and then choose "Create Map" on the Maps tab.
There is an option in Google Maps API DirectionsRequest called optimizeWaypoints, which should do what you want. This can only handle up to 8 waypoints, though.
Alternatively, there is an open source (MIT license) library that you can use with the Google Maps API to get an optimal (up to 15 locations) or pretty close to optimal (up to 100 locations) route.
See http://code.google.com/p/google-maps-tsp-solver/
You can see the library in action at www.optimap.net
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