Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Distance Matrix Api: travel time with traffic

I am trying to get the travel time with traffic between 2 sets of lat/long coordinates. I can call the Google Distance Matrix API, but I am only getting travel time without traffic. The API notes which I have read say to use a parameter called departure_time. Here is the excerpt:

departure_time specifies the desired time of departure as seconds since midnight, January 1, 1970 UTC. The departure time may be specified by Maps for Business customers for to specify the departure_time to receive trip duration considering current traffic conditions. The departure_time must be set to within a few minutes of the current time.

I found this website to give me that time: epochconverter

However I am still getting the same travel time every time. Here is a sample request, the departure_time parameter would need to be updated (not that it matters).

https://maps.googleapis.com/maps/api/distancematrix/xml?units=imperial&departure_time=1408046331&origins=37.407585,-122.145287&destinations=37.482890,-122.150235

15 minutes is always returned.

Using "maps dot google dot com" a travel time of 19 mins is returned when traffic is taken into account.

If anyone can help me get the travel time with traffic from the Distance Matrix API, that would be greatly appreciated.

like image 388
Brian Schmid Avatar asked Aug 14 '14 20:08

Brian Schmid


2 Answers

No need for business license, just need an API key from project on https://console.developers.google.com/ with Google distance Matrix enabled. For results as on google map use traffic_model with values pessimistic,optimistic and do keep in mind "The departure_time must be set to within a few minutes of the current time" without that it will always return 15 minutes.

like image 93
Hriday Nath Tripathi Avatar answered Sep 30 '22 21:09

Hriday Nath Tripathi


That feature appears to only be available to Maps for Business customers, according to the docs.

like image 30
vch Avatar answered Sep 30 '22 19:09

vch