This page describes how to create routes and add custom attributes using the Roads Selection API in the following sections:
- Route length and selection guidelines: Review route length limits, short-segment trade-offs, and selection best practices before defining routes.
- Create a route: Define a single route using the
createendpoint. - Batch create routes: Define multiple routes in a single
request using the
batchCreateendpoint. - Create a route with intermediate waypoints: Define a route with up to 25 intermediate waypoints.
- Utilize custom route attributes: Add up to 25 custom key-value pairs to your routes for organizational purposes.
To configure and export route definitions visually, see Tools and resources. To review strategies for complex road geometries, see the Roads Management Insights route selection guide.
Route length and selection guidelines
Before you create a SelectedRoute, consider how route length, road
traffic volume, and intersections affect validation and data quality.
Length limits and minimum route length
The Roads Selection API enforces two synchronous length limits when you create or update a route:
- Non-zero length: Every route must have a length greater than zero. A route has zero length when its origin, destination, and every intermediate waypoint have identical coordinates.
- Maximum length of 100 km: The computed driving path can't exceed
100 km. The API measures the computed driving path from the routing
backend rather than straight-line distance. Routes with a zero-length path
or a computed driving path longer than 100 km fail immediately with an
INVALID_ARGUMENTerror.
The API doesn't enforce a fixed minimum route length above zero. Instead, whether a short route passes asynchronous road utility validation depends on road traffic volume and whether the route spans intersections.
Short segments and traffic lights
You might define short mid-block segments of around 100 m between intersections to isolate road speed from traffic-light cycle variance. How well these short segments perform depends on the traffic volume of the road:
- High-traffic roads: Short mid-block segments without intersections on major arterials and highways typically pass road utility validation.
- Moderate- or lower-traffic roads: Omitting intersections increases the
chance that a route fails validation with
VALIDATION_ERROR_LOW_ROAD_USAGE, because stricter traffic volume requirements apply when a route doesn't span intersections. Short segments on less busy roads also have fewer real-time data points, so their travel times vary more, and a waypoint that snaps a few meters off covers a larger share of the route.
Best practices for reliable routes
Follow these practices to define routes that validate reliably and produce consistent travel-time data:
- Span intersections on less busy roads: On moderate- or lower-traffic roads, extend short segments to include one or more intersections.
- Anchor route geometry: Keep default fixed routing with
dynamicRoutingset tofalsefor consistent baseline comparisons. Include at least one intermediate waypoint to anchor the path geometry. - Verify validation state: Check the
statefield using thegetendpoint or the BigQueryroutes_statustable to confirm the route reachesSTATE_RUNNING.
For validation states and troubleshooting steps, see Understand route validation. For road utility requirements, see Usage guidelines and limitations. For more route-sizing examples, see the Roads Management Insights route selection guide.
Create a route
To create a route, send a POST request to the create endpoint.
https://roads.googleapis.com/selection/v1/projects/PROJECT_NUMBER/selectedRoutes?selectedRouteId=SELECTED_ROUTE_ID
The request body must be a JSON object that defines the SelectedRoute
resource. This object specifies the following information:
- A
dynamicRouteobject with the following information:- The
originof the selected route. - The
destinationof the selected route. - Any
intermediates, also known as waypoints, of the route.
- The
- A unique
selectedRouteId. This value should be 4-63 characters, and valid characters area-z,A-Z,0-9,-, or_. If an ID is not provided, the system generates a unique ID for the selected route.
Create a fixed route (default)
Routes are created as fixed routes by default and stay consistent with the
static route geometry (exported to the routes_status BigQuery table)
calculated at creation time without live traffic. This ensures consistent
traffic data monitoring without being affected by traffic condition changes.
You can set the dynamicRouting boolean field in the request body to
specify whether the route is fixed (false, the default) or dynamic (true).
The following code sample shows the structure of a POST request to
create a fixed route.
curl -X POST -d '
{
"dynamicRoute": {
"origin": {
"latitude": ORIGIN_LATITUDE,
"longitude": ORIGIN_LONGITUDE
},
"destination": {
"latitude": DESTINATION_LATITUDE,
"longitude": DESTINATION_LONGITUDE
}
}
}' \
-H 'X-Goog-User-Project: PROJECT_NUMBER' \
-H 'Content-Type: application/json' \
-H "Authorization: Bearer ACCESS_TOKEN" \
"https://roads.googleapis.com/selection/v1/projects/"\
"PROJECT_NUMBER/selectedRoutes?selectedRouteId=SELECTED_ROUTE_ID"On success, the API returns the SelectedRoute resource. The response
includes the selectedRouteId in the name field. You can use this
selectedRouteId to retrieve or delete the SelectedRoute resource.
The following code sample shows the structure of a successful
create
endpoint response.
{
"name": "projects/PROJECT_NUMBER/selectedRoutes/SELECTED_ROUTE_ID",
"dynamicRoute": {
"origin": {
"latitude": ORIGIN_LATITUDE,
"longitude": ORIGIN_LONGITUDE
},
"destination": {
"latitude": DESTINATION_LATITUDE,
"longitude": DESTINATION_LONGITUDE
}
},
"createTime": "CREATE_TIME",
"state": "STATE_VALIDATING",
"dynamicRouting": false
}
Create a dynamic route
Optionally, you can create a dynamic route by setting the dynamicRouting
field to true. The route geometry can change due to varying traffic conditions
because Google's routing platform finds the best route every time.
The following code sample shows the structure of a POST request to
create a dynamic route:
curl -X POST -d '
{
"dynamicRoute": {
"origin": {
"latitude": ORIGIN_LATITUDE,
"longitude": ORIGIN_LONGITUDE
},
"destination": {
"latitude": DESTINATION_LATITUDE,
"longitude": DESTINATION_LONGITUDE
}
},
"dynamicRouting": true
}' \
-H 'X-Goog-User-Project: PROJECT_NUMBER' \
-H 'Content-Type: application/json' \
-H "Authorization: Bearer ACCESS_TOKEN" \
"https://roads.googleapis.com/selection/v1/projects/"\
"PROJECT_NUMBER/selectedRoutes?selectedRouteId=SELECTED_ROUTE_ID"The following code sample shows the structure of a successful create
endpoint response.
{
"name": "projects/PROJECT_NUMBER/selectedRoutes/SELECTED_ROUTE_ID",
"dynamicRoute": {
"origin": {
"latitude": ORIGIN_LATITUDE,
"longitude": ORIGIN_LONGITUDE
},
"destination": {
"latitude": DESTINATION_LATITUDE,
"longitude": DESTINATION_LONGITUDE
}
},
"createTime": "CREATE_TIME",
"state": "STATE_VALIDATING",
"dynamicRouting": true
}
Create a route with intermediate waypoints
To create a route that passes through specific points between the origin and
destination, include an intermediates array within the
dynamicRoute object in your request body. Each element in the
intermediates array is a waypoint defined by its latitude and
longitude. A route can have up to 25 waypoints.
For best practices on placing intermediate waypoints on divided highways, multi-level overpasses, and tunnels, see the Roads Management Insights route selection guide.
The following code sample shows how to create a SelectedRoute with
intermediate waypoints:
curl -X POST -d '
{
"dynamicRoute": {
"origin": {
"latitude": ORIGIN_LATITUDE,
"longitude": ORIGIN_LONGITUDE
},
"intermediates": [
{"latitude": INTERMEDIATE_LATITUDE_1, "longitude": INTERMEDIATE_LONGITUDE_1},
{"latitude": INTERMEDIATE_LATITUDE_2, "longitude": INTERMEDIATE_LONGITUDE_2},
{"latitude": INTERMEDIATE_LATITUDE_3, "longitude": INTERMEDIATE_LONGITUDE_3}
],
"destination": {
"latitude": DESTINATION_LATITUDE,
"longitude": DESTINATION_LONGITUDE
}
}
}' \
-H 'X-Goog-User-Project: PROJECT_NUMBER' \
-H 'Content-Type: application/json' \
-H "Authorization: Bearer ACCESS_TOKEN" \
"https://roads.googleapis.com/selection/v1/projects/"\
"PROJECT_NUMBER/selectedRoutes?selectedRouteId=SELECTED_ROUTE_ID"Utilize custom route attributes
To enhance your route management and data analysis within Roads Management Insights,
the SelectedRoute object includes a routeAttributes field.
Use the routeAttributes field to define your own custom properties for
individual routes, where each attribute is a key-value pair. You can provide up
to 25 custom key-value pairs per route.
These attributes are useful for identifying specific routes or for grouping routes based on criteria relevant to your needs.
The following are some examples of route attributes you could use:
"road_classification": "highway""maintenance_zone": "north_district""event_id": "marathon_2024""pavement_type": "asphalt"
Follow the next guidelines when defining the routeAttributes field:
- Keys must not begin with the prefix
goog. - The length of each key and each value must not exceed 100 characters.
You can then use these custom routeAttributes within Roads Management Insights
in the following ways:
- Filter Pub/Sub notifications: You can set filters on your Pub/Sub subscriptions to receive updates only for routes that match or don't match specific attribute keys and their corresponding values.
- Refine BigQuery analysis: In your BigQuery tables, you can use these attributes to filter for specific routes based on an attribute's value. You can also group routes by a specific attribute key for more targeted data analysis.
The next code sample shows how to create a SelectedRoute with custom
routeAttributes.
curl -X POST -d '
{
"dynamicRoute": {
"origin": {
"latitude": ORIGIN_LATITUDE,
"longitude": ORIGIN_LONGITUDE
},
"destination": {
"latitude": DESTINATION_LATITUDE,
"longitude": DESTINATION_LONGITUDE
}
},
"routeAttributes": {
"ATTRIBUTE_KEY": "ATTRIBUTE_VALUE"
}
}' \
-H 'X-Goog-User-Project: PROJECT_NUMBER' \
-H 'Content-Type: application/json' \
-H "Authorization: Bearer ACCESS_TOKEN" \
"https://roads.googleapis.com/selection/v1/projects/"\
"PROJECT_NUMBER/selectedRoutes?selectedRouteId=SELECTED_ROUTE_ID"Batch create routes
To create multiple routes in a single request, use the
batchCreate
endpoint. This endpoint lets you define up to 1000 routes in one call.
Send a POST request to the batchCreate endpoint:
https://roads.googleapis.com/selection/v1/projects/PROJECT_NUMBER/selectedRoutes:batchCreate
The URL uses gRPC Transcoding syntax.
The request body must be a JSON object containing a requests array.
Each object within this array is a CreateSelectedRouteRequest that
defines an individual SelectedRoute resource.
The following code sample shows the structure of a POST request to the
batchCreate endpoint:
curl -X POST -d '
{
"requests": [
{
"selectedRoute": {
"dynamicRoute": {
"origin": {
"latitude": ORIGIN_LATITUDE_1,
"longitude": ORIGIN_LONGITUDE_1
},
"destination": {
"latitude": DESTINATION_LATITUDE_1,
"longitude": DESTINATION_LONGITUDE_1
}
}
},
"selectedRouteId": "route-one"
},
{
"selectedRoute": {
"dynamicRoute": {
"origin": {
"latitude": ORIGIN_LATITUDE_2,
"longitude": ORIGIN_LONGITUDE_2
},
"destination": {
"latitude": DESTINATION_LATITUDE_2,
"longitude": DESTINATION_LONGITUDE_2
}
}
},
"selectedRouteId": "route-two"
}
]
}' \
-H 'X-Goog-User-Project: PROJECT_NUMBER' \
-H 'Content-Type: application/json' \
-H "Authorization: Bearer ACCESS_TOKEN" \
"https://roads.googleapis.com/selection/v1/projects/"\
"PROJECT_NUMBER/selectedRoutes:batchCreate"On success, the API returns a response containing an array of the
SelectedRoute resources that were created.
The following code sample shows the structure of a batchCreate endpoint
response:
{
"selectedRoutes": [
{
"name": "projects/PROJECT_NUMBER/selectedRoutes/SELECTED_ROUTE_ID_1",
"dynamicRoute": {
"origin": {
"latitude": ORIGIN_LATITUDE_1,
"longitude": ORIGIN_LONGITUDE_1
},
"destination": {
"latitude": DESTINATION_LATITUDE_1,
"longitude": DESTINATION_LONGITUDE_1
}
},
"createTime": "CREATE_TIME_1",
"state": "STATE_VALIDATING",
"dynamicRouting": false
},
{
"name": "projects/PROJECT_NUMBER/selectedRoutes/SELECTED_ROUTE_ID_2",
"dynamicRoute": {
"origin": {
"latitude": ORIGIN_LATITUDE_2,
"longitude": ORIGIN_LONGITUDE_2
},
"destination": {
"latitude": DESTINATION_LATITUDE_2,
"longitude": DESTINATION_LONGITUDE_2
}
},
"createTime": "CREATE_TIME_2",
"state": "STATE_VALIDATING",
"dynamicRouting": false
}
]
}