Get a route token

  • To get a route token from the Routes API, you must set travelMode to DRIVE and routingPreference to either TRAFFIC_AWARE or TRAFFIC_AWARE_OPTIMAL.

  • Ensure that none of your route waypoints are via waypoints when requesting a route token.

  • Use the routes.routeToken field mask in your request to ensure that a route token is returned.

  • The route generated with a token may vary slightly from the planned route due to dynamic road conditions, and it's recommended to use the token soon after generation.

  • The route token can be used in the Navigation SDK for your planned route.

European Economic Area (EEA) developers

To request that the Compute Routes returns route tokens for generated routes, follow these steps:

  1. Set the following parameters required to return a route token:

    • Set travelMode to DRIVE.
    • Set routingPreference to TRAFFIC_AWARE or TRAFFIC_AWARE_OPTIMAL.
  2. Check that none of your route waypoints are via waypoints.

  3. Specify the routes.routeToken field mask to return a route token:

    X-Goog-FieldMask: routes.routeToken
    

You can use the route token for your planned route in the Navigation SDK. For more details, see:

Route token example

Here's an example curl request body for a single origin, single-destination route. It uses field masks to request a route token, along with the route duration, distance, and route polyline:

curl -X POST -d
{"origin":{
    "location": {
        "latLng":{
            "latitude":  -37.8167,
            "longitude": 144.9619
        }
    }
},
"destination":{
    "location": {
        "latLng":{
            "latitude":-37.8155,
            "longitude": 144.9663
        }
    }
},
"routingPreference":"TRAFFIC_AWARE",
"travelMode":"DRIVE"
}
-H 'X-Goog-Api-Key: YOUR_API_KEY' \
-H X-Goog-FieldMask: routes.routeToken,routes.duration,routes.distanceMeters,routes.polyline.encodedPolyline
'https://routes.googleapis.com/directions/v2:computeRoutes'

For more details, see the Compute Routes API reference.