Optimizing route with traffic information

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 :

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?

Thanks a lot!

The google api as per your links seems to allow for traffic sensitive planning, assuming you want to be billed against higher rate

Who is paying the api bill?

My 2centd. No code example and I guess not needed

So from what you understand, it should be possible to do, but might cost more on the API bill side of things?
I will be responsible for paying that API bill.

I just want to make sure it’s possible, and if so (and if anybody knows where to look), where could I get an article or documentation about how to make it work. Like a simple example of a map with waypoints, considering traffic information.

Thanks a lot!

The link u gave has it all

It says

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.

But I need to use “stopover waypoints”. Does that mean I’m screwed? I can’t believe I cannot use stopover waypoints and traffic info at the same time?

Then you request individual routes between stops and summarise

Oh, so taking the Route that has destination A > B > C > D, and treating it as:
A > B (get traffic info)
then
B > C (get traffic info)
then finally
C > D.
Treating everything as individual routes.
That’s a great idea. Thanks!

1 Like