How can I prevent the results produced by Google Maps API v3 DirectionsService being influenced by current traffic conditions?

StackOverflow https://stackoverflow.com/questions/12479715

Question

I have written a website that uses the DirectionsService of Google Maps API v3 to find the driving distance between two user-defined locations.

I have found that it produces different results at different times of day or different days of the week.

For example, I have run a journey between Coatbridge and Grangemouth on two separate occasions the first time it told me the distance was 41.8km, the second time it said it was 39.9km.

I suspect it could be influenced by current traffic conditions, perhaps. I have found no clues within the Google documentation.

Has anyone else come across this problem? More importantly, does anyone have a solution?

Edit:
It seems that the influence of current traffic conditions is a known 'function' of the Google Maps DirectionsService (thanks for your input @vitors), but, as yet, no one has come forward with a method to 'turn off' this functionality.

How can I prevent the results being influenced by current traffic conditions? Can anyone help, please?

Edit: It seems Google have finally added a durationInTraffic parameter (thanks for the info @Ron). Shame it's nearly 2 years too late for me! Hope this is useful for someone else.

Was it helpful?

Solution

You could try setting durationInTraffic as false.

OTHER TIPS

Your suspicion is correct, the result is influenced by traffic conditions.

I think that this post can explain http://searchengineland.com/traffic-estimates-return-to-google-maps-116862.

If you want to provide only one point to the user and it should be the shortest distance, what you can do is, specify the optimizeWaypoints (optional) parameter while calling distance service for Google. After using this option, the first result in the array that you will get will hold your shortest distance and will always be the same:

For more information you can follow this link: https://developers.google.com/maps/documentation/javascript/directions

and search for optimizeWaypoints

Happy Coding.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top