Page Summary
-
The Routes API offers route options tailored to various vehicle types, including cars, two-wheelers, transit, and eco-friendly options, or defaults to a gasoline car if unspecified.
-
You can specify your preferred mode of transportation using the
travelModeparameter, selecting from options such as transit, driving, two-wheeled vehicles, walking, or bicycling. -
Walking, bicycling, and two-wheel routes are currently in beta and may lack comprehensive pedestrian or cycling paths, requiring a user warning in your application.
You can get a route suited to different types of vehicles. If you don't specify
a vehicle type, the Routes API uses the default of a gasoline-powered
car
(DRIVE).
To set the mode of transportation in a
computeRoutes
HTTP POST request, pass the
travelMode
field in the JSON request body using a
RouteTravelMode
enum value, with choices of transit, driving, two-wheeled vehicles, trucks,
walking, or bicycling.
| Vehicle type | RouteTravelMode value |
Description |
|---|---|---|
| Bicycle | BICYCLE |
Compute a route for bicycles and other human-powered travel. For motorized two-wheeled vehicles, see Two-wheeled vehicle. |
| Drive | DRIVE |
Compute a driving route.
DRIVE
is the default if you don't specify a vehicle type. |
| Transit | TRANSIT |
Get a transit route for navigation instructions using the public transportation options available in the region. Transit options can include buses, subways, and trains, among others. A transit route also usually includes instructions on walking to, from, and between transit stations. |
| Two-wheeled vehicle | TWO_WHEELER |
Two-wheeler refers to two-wheeled motorized vehicles (for example, motorcycles). The two-wheeler travel mode differs from the bicycle travel mode, which is a human-powered travel mode. |
| Truck | TRUCK |
Compute a route customized for a large vehicle by specifying its
physical attributes and constraints in
routeModifiers.vehicleInfo.
Use this vehicle type to avoid low bridges, weight restrictions, and
hazards. |
| Walk | WALK |
Compute a walking route. |
Specify the travel mode in a request
To specify a travel mode in a
computeRoutes
request, set the
travelMode
field in the HTTP POST JSON request body and include the required
X-Goog-FieldMask header to select the
Route
response fields you need. If you're migrating from the legacy Directions API,
the
travelMode
field in the POST JSON request body replaces the legacy mode URL query
parameter. For more information, see
Migrate to the Routes API.
curl -X POST -d '{ "origin": { "location": { "latLng": { "latitude": 37.419734, "longitude": -122.0827784 } } }, "destination": { "location": { "latLng": { "latitude": 37.417670, "longitude": -122.079595 } } }, "travelMode": "BICYCLE" }' \ -H 'Content-Type: application/json' -H 'X-Goog-Api-Key: YOUR_API_KEY' \ -H 'X-Goog-FieldMask: routes.duration,routes.distanceMeters,routes.polyline.encodedPolyline' \ 'https://routes.googleapis.com/directions/v2:computeRoutes'