The traffic preferences you select balance the accuracy of the route details with request performance in one of two ways:
Traffic aware -- Return the most accurate results possible (higher latency).
Traffic unaware -- Return the results as quickly as possible (lowest latency).
When you make a request, weigh whether it is better to return the most accurate results possible, or to return results as quickly as possible. The Routes API provides options that let you control the quality of the response data versus the latency of the response.
How to set the traffic level
The Routes API provides RoutingPreference (REST) and RoutingPreference (gRPC) that let you specify routing preferences for calculating routes.
The default is traffic unaware results. You select traffic options with the
TRAFFIC_UNAWARE
, TRAFFIC_AWARE
and TRAFFIC_AWARE_OPTIMAL
routing
preferences. Each routing preference produces results that differ in route
quality, estimated ETA, and response latency.
Traffic conditions
Traffic conditions characterize the rate of traffic flow:
Normal traffic: No congestion with traffic flowing at a normal speed.
Light to moderate traffic: Increasing congestion, with traffic flowing at a reduced speed.
Heavy traffic: Severe congestion, with heavily reduced traffic speed.
Traffic unaware
TRAFFIC_UNAWARE
is the default setting. Use this routing preference when you
want responses returned the quickest, and approximate routing details are good
enough.
TRAFFIC_UNAWARE
routes are calculated without accounting for current traffic
conditions. This routing preference results in the fastest request response
(lowest latency).
If you choose TRAFFIC_UNAWARE
,
the route and duration chosen are based on road network and average time-independent
traffic conditions, not current road conditions. Consequently, routes may include roads
that are temporarily closed. Results for a given request may vary over time
due to changes in the road network, updated average traffic conditions,
and the distributed nature of the service. Results may also vary between
nearly-equivalent routes at any time or frequency.
Here are the responses you'll see:
duration
- Contains the ETA for the route.staticDuration
: The ETA for the route considering only historical traffic information. ForTRAFFIC_UNAWARE
, this contains the same value asduration
.
Traffic aware
Use this routing preference when you want more accurate routing details than
TRAFFIC_UNAWARE
, and yet you don't mind if responses are returned with a
moderate increase in latency.
When you set the TRAFFIC_AWARE
routing preference, the service calculates the
route considering current traffic conditions. As a result, the route and route
details more accurately reflect real-world conditions. Because this increase in
data quality comes at the expense of response latency, performance optimizations
are applied to reduce much of the latency.
Here are the responses you'll see:
duration
: The ETA considering real-time traffic information.staticDuration
The ETA for the route considering only historical traffic information.
Traffic aware optimal
Use this routing preference when you want results of the highest quality without regard to how long responses take. This routing preference has the longest delay in returning responses (highest latency).
When you set the TRAFFIC_AWARE_OPTIMAL
routing preference, the service
calculates the route considering current traffic conditions, but doesn't apply
performance optimizations. In this mode, the server performs a more exhaustive
search of the road network to find the optimal route.
The TRAFFIC_AWARE_OPTIMAL
routing preference is equivalent to the mode used by
maps.google.com and by the
Google Maps mobile app.
When you use this option with Compute Route Matrix, the number of elements in a request (number of origins × number of destinations) cannot exceed
- For more on Compute Route Matrix limits, see Compute a route matrix.
Here are the responses you'll see:
duration
: The ETA for the route considering real-time traffic information.staticDuration
: The ETA for the route considering only historical traffic information.
Set departure time (optional)
Use this property only for traffic aware requests where the departure time needs
to be in the future. If you don't set the departureTime
property, it defaults
to the time that you make the request.
Use the departureTime
property along with the TRAFFIC_AWARE
and
TRAFFIC_AWARE_OPTIMAL
options when you want to adjust the way the service
predicts traffic when choosing a route.
TRAFFIC_UNAWARE
: Not recommended because the choice of route and duration are based on the road network and average time-independent traffic conditions.TRAFFIC_AWARE
andTRAFFIC_AWARE_OPTIMAL
: Recommended for departures happening in the near future because these preferences take live traffic conditions into consideration. Live traffic becomes more important and relevant the closer thedepartureTime
is to now. The farther ahead you set the departure time into the future, the more consideration is given to historical traffic conditions in selecting routes.
Example: How to select traffic aware routing
The following JSON code demonstrates how to set the TRAFFIC_AWARE_OPTIMAL
routing preference in a request message entity body.
{ "origin":{ "location":{ "latLng":{ "latitude":37.419734, "longitude":-122.0827784 } } }, "destination":{ "location":{ "latLng":{ "latitude":37.417670, "longitude":-122.079595 } } }, "travelMode":"DRIVE", "routingPreference":"TRAFFIC_AWARE_OPTIMAL" }
Configure traffic on polylines
The Routes API lets you request information about traffic conditions along a traffic-aware polyline. See Request polylines for more information.