Create the selected-route

Create a selected-route by sending a POST request to the create selected-routes endpoint:

https://roads.googleapis.com/selection/v1/projects/PROJECT_NUMBER/selectedRoutes?selectedRouteId=SELECTED_ROUTE_ID

Pass a JSON body to the request defining the selected-route. You must:

  • Specify the origin of the selected-route.

  • Specify the destination of the selected-route.

For example:

curl -X POST -d '
    {"dynamic_route": { origin: {latitude: 37.78 ,longitude: -122.41}, destination: {latitude: 37.74, longitude: -122.42}}}' \
  -H 'X-Goog-User-Project: PROJECT_NUMBER' \
  -H 'Content-Type: application/json' \
  -H "Authorization: Bearer $TOKEN" \
  "https://roads.googleapis.com/selection/v1/projects/PROJECT_NUMBER/selectedRoutes?selectedRouteId=sample-route"

On success, the response contains the ID of the selected-route, in the form projects/PROJECT_NUMBER/selectedRoutes/SELECTED_ROUTE_ID along with additional information. Use the selected-route-id when making requests to retrieve or delete the selected-route.

{
  "name": "projects/PROJECT_NUMBER/selectedRoutes/sample-route",
  "dynamicRoute": {
    "origin": {
      "latitude": 37.78,
      "longitude": -122.41
    },
    "destination": {
      "latitude": 37.74,
      "longitude": -122.42
    }
  },
  "createTime": "2024-08-29T18:24:37.882843Z",
  "state": "STATE_SCHEDULING"
}

Utilize Custom Route Attributes

To enhance your route management and analysis, the SelectedRoute object includes a route_attributes field. Use route_attributes to define your own custom properties for individual routes, where each attribute is a key-value pair. You can provide up to 10 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.

When you define route_attributes:

  • Keys must not begin with the prefix goog.
  • The length of each key and each value must not exceed 100 characters.

You can use these custom route_attributes 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.

Below is a sample example for creating selected_route with custom route_attributes:

curl -X POST -d '
    {"dynamic_route": { origin: {latitude: 37.78 ,longitude: -122.41}, destination: {latitude: 37.74, longitude: -122.42}}, route_attributes: {"route_type":"highway"}}' \
  -H 'X-Goog-User-Project: PROJECT_NUMBER' \
  -H 'Content-Type: application/json' \
  -H "Authorization: Bearer $TOKEN" \
  "https://roads.googleapis.com/selection/v1/projects/PROJECT_NUMBER/selectedRoutes?selectedRouteId=sample-route"