| Forum | GitHub | Maps | Blog

Traffic for Route Optimization


Hey there,

I’m trying to add traffic at a given time to the calculations made by the Route Optimization API. I found support for custom Cost Matrices to be almost exactly what I need:

However there’s one catch: requests to the custom cost matrix api does not include a time. Therefore it’s impossible to estimate traffic for a given route.

To be more specific, I tried to use the Google Maps API for calculating cost matrices including traffic. That API does not account for traffic if no departureTime is passed.

Here are the parameters given to the custom cost matrix api: /api/graphhopper/graphhopper_matrix?&vrp_job_id=4230aaaf-04f9-4c67-bb74-8b7832fbfc4e&vehicle=car&origins=48.218116%2C16.456655%7C48.215455%2C16.38034%7C48.221343%2C16.351241%7C48.16883%2C16.367282%7C48.23812%2C16.4763%7C48.235223%2C16.465343%7C48.214199%2C16.380166%7C48.212085%2C16.462936&destinations=48.218116%2C16.456655%7C48.215455%2C16.38034%7C48.221343%2C16.351241%7C48.16883%2C16.367282%7C48.23812%2C16.4763%7C48.235223%2C16.465343%7C48.214199%2C16.380166%7C48.212085%2C16.462936&mode=car

So, two questions:

  1. is it possible to pass the time as a parameter to custom cost matrix api?
  2. if not, how would you estimate traffic for route optimization?



Hi Tom,
Good point. It is not possible to specify departure times yet. Currently, you can only optimize with one specific matrix (that represents for example a peak-hour traffic matrix). Thus, you need to specify the departure time for the custom matrix for your own.
Apart from that the optimization API cannot yet account for traffic. However, it offers a “speed_factor” you can use to slow down your vehicles for the optimization. It is described here.

To give you an outlook, our plan is to include traffic by the end of this year.



Thanks for the quick answer! Can’t wait to see you include traffic in calculations.


Is there a current update on this timeline?


Unfortunately not. We are still discussing terms and other things with the different providers and then it will take further time to have the technical integration. We’ll update here once we know more.

Just to give some clarification: this will not include real time traffic in the first place instead we will provide different speed estimates depending on the time in the future.


For our use case (Food service deliveries) the time/traffic thing is an issue. We are seeing our users using delivery windows to try to bias Graphhopper away from known rush hour blackspots and, of course, getting it wrong :frowning:

If Graphhopper could use something like a weighted average over the past few weeks of traffic speed that would go a long way towards solving the problem (routes are planned and loaded the night before so live traffic is no help).

One related thought… I wonder how many Graphhopper users are capturing GPS info as the vehicles progress through the day. We are and I’d be quite happy to share that data with Graphhopper so you could build your own real-world speed tables for roads.

The data we have is ‘only’ from a mobile phone’s GPS so it’s not wonderfully accurate but you’re good at clever mathematics so could hopefully ‘normalise’ the data.


You can now use this: Traffic and day time dependent optimization and the public beta will start in a few days.