Reputation: 1699
Hopefully this question will make sense. I am working with a programmer for an Ionic app that uses Google Maps API to allow the user to create custom routes with multiple waypoints.
It's a route planner app.
there's a "Optimize my route" button, that checks if the order you have entered the waypoints are the best way to save time during that trip. If not, it will rearrange your route to make sure you don't waste time.
I asked my programmer to make sure it takes in consideration the traffic data when you press the "Optimize my route" button, but he says it's impossible to do, based on this API documentation :
https://developers.google.com/maps/documentation/directions/intro#DirectionsAdvanced
He says it can only optimize the route taking in consideration the regular travel time, without traffic information.
I trust him, but I find it hard to believe that it's impossible to optimize a route with traffic info in mind with the Google Maps API.
Any thoughts or example that would help me out?
EDIT :
The part of the documentation that seems to make it impossible is :
Traffic information is used when all of the following apply :
-...
-...
-The request does not include stopover waypoints. If the request includes waypoints, prefix each waypoint with via: to influence the route but avoid stopovers.
The app uses stopovers waypoints to allow the user to create a route. Is there any workaround? "Via" seems to be a good alternative, but wouldn't allow the user to tell the app how long he's staying at a specific event.
Thanks
Upvotes: 0
Views: 4114
Reputation: 32158
I believe your developer is completely right. There is no way to optimize a route taking into account current traffic conditions in Directions API. If we check documentation we can see the following statement about optimization
By default, the Directions service calculates a route through the provided waypoints in their given order. Optionally, you may pass optimize:true as the first argument within the waypoints parameter to allow the Directions service to optimize the provided route by rearranging the waypoints in a more efficient order. (This optimization is an application of the traveling salesperson problem.) Travel time is the primary factor which is optimized, but other factors such as distance, number of turns and many more may be taken into account when deciding which route is the most efficient. All waypoints must be stopovers for the Directions service to optimize their route.
source: https://developers.google.com/maps/documentation/directions/intro#OptimizeWaypoints
On the other hand if you check duration in traffic section of documentation it states
Traffic information is used when all of the following apply (these are the conditions required to receive the duration_in_traffic field in the Directions response):
- The travel mode parameter is driving, or is not specified (driving is the default travel mode).
- The request includes a valid departure_time parameter. The departure_time can be set to the current time or some time in the future. It cannot be in the past.
- The request does not include stopover waypoints. If the request includes waypoints, prefix each waypoint with via: to influence the route but avoid stopovers.
source: https://developers.google.com/maps/documentation/directions/intro#DirectionsAdvanced
Note sentences marked in bold. Unfortunately, traffic info doesn't allow stopovers that are required for route optimization.
Upvotes: 2