Search code examples
google-mapsdirections

Google Directions API Duration In Traffic


I noticed when using the Google Directions API web service when the request contains more than 1 leg the response does not include the duration in traffic information. With 1 leg requests the duration in traffic is present in the response. Why is this?

 https://maps.googleapis.com/maps/api/directions/json?origin=50.7963874022473,-1.12215042114258&destination=50.8525337185711,-1.17932204157114&waypoints=50.7921245679458,-1.13072438976753&mode=driving&departure_time=1452940200&traffic_model=pessimistic&units=imperial&key=myKey

In the above request no Duration in traffic but in the below request

https://maps.googleapis.com/maps/api/directions/json?origin=50.7963874022473,-1.12215042114258&destination=50.8525337185711,-1.17932204157114&mode=driving&departure_time=1452940200&traffic_model=pessimistic&units=imperial&key=myApi

The duration In Traffic is present.


Solution

  • You can prefix waypoints with via: and this will return a response with just one leg and include the duration in traffic field.(so long as the correc parameters are included).

     https://developers.google.com/maps/documentation/directions/intro?hl=en