Reputation: 269
Is it possible to get a response (true or false) if are a traffic jam from your position to your destination, using google maps android API? Or using google maps web api?
Can not find anythink about that.
Upvotes: 1
Views: 4794
Reputation: 32178
I believe there is no direct Google endpoint that can answer this question. However, you can implement a workaround using a Distance Matrix API web service or Directions API web service. If you specify a departure time in the request, the response will contain fields duration
and duration_in_traffic
. So you can figure out if duration_in_traffic
is much bigger than duration
and decide if there is a traffic jam somewhere on this route.
For example,
I execute Distance Matrix API request for two points in Barcelona
https://maps.googleapis.com/maps/api/distancematrix/json?origins=av%20Diagonal%20198%2C%20Barcelona&destinations=plaza%20Espa%C3%B1a%2C%20Barcelona&departure_time=now&key=MY_API_KEY
The response is
{
"destination_addresses":[
"Av. del Paraŀlel, s/n, 08015 Barcelona, Spain"
],
"origin_addresses":[
"Avinguda Diagonal, 198, 08018 Barcelona, Spain"
],
"rows":[
{
"elements":[
{
"distance":{
"text":"6.0 km",
"value":6049
},
"duration":{
"text":"17 mins",
"value":1035
},
"duration_in_traffic":{
"text":"19 mins",
"value":1134
},
"status":"OK"
}
]
}
],
"status":"OK"
}
Comparing duration_in_traffic
and duration
from my response I can say that currently there are no traffic jams on this route.
I hope this helps!
Upvotes: 2