Get a route token

To request that the Routes API 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.