Get a shorter distance route

The Routes API can return driving routes optimized for a shorter travel distance when you enable shorter distance routes.

When you request a shorter distance route, the service returns the following:

  • The default route, which is a route optimized primarily for ETA.
  • A shorter route optimized for minimizing travel distance across the entire trip.

What it is and why to use it

A shorter distance route prioritizes distance over driving comfort or speed. For example, it may prefer local roads instead of highways, take dirt roads, or cut through parking lots. It does not return any maneuvers that Google Maps knows to be illegal.

Request a shorter distance route

Your request must meet the following criteria:

  • Set travelMode to DRIVE, BICYCLE, or TWO_WHEELER.
  • Set requestedReferenceRoutes to SHORTER_DISTANCE.
  • Set a response field mask to return the response properties associated with a shorter-distance route:
    • routes.routeLabels: Identifies each route as either DEFAULT_ROUTE, SHORTER_DISTANCE, or DEFAULT_ROUTE_ALTERNATE.
    • routes.routeToken: A route token that you can pass to the Navigation SDK to retrieve a custom route.
  • Don't include any Via intermediate waypoints.
  • Don't include the optimizeWaypointOrder parameter.
  • Optional: Set a response field mask to return the following properties associated with both the default and shorter-distance route:
    • routes.distanceMeters: Returns the distance of the route.
    • routes.duration: Returns the duration of the route.

For reference information, see ReferenceRoute and RouteLabel.

Example request: Shorter distance route

The following code shows a request for a shorter distance route. In this example, you use the response field mask to return fields associated with both the default and shorter-distance route with the following field masks:

  • routes.distanceMeters
  • routes.duration
curl -X POST -H 'content-type: application/json' -d '{
  "origin": {
    "location": {
      "latLng": {
        "latitude": 41.76904801292959,
        "longitude": -72.67374935684933
      }
    }
  },
  "destination": {
    "location": {
      "latLng": {
        "latitude": 41.823042361105024,
        "longitude": -71.40933143059424
      }
    }
  },
  "travelMode":"DRIVE",
  "routingPreference":"TRAFFIC_AWARE",
  "requestedReferenceRoutes": ["SHORTER_DISTANCE"],
}' \
-H 'Content-Type: application/json' -H 'X-Goog-Api-Key: YOUR_API_KEY \
-H 'X-Goog-FieldMask: routes.distanceMeters,routes.duration,routes.routeLabels,routes.routeToken' \
'https://routes.googleapis.com/directions/v2:computeRoutes'

Example shorter route response

{
  "routes": [
    {
      "distanceMeters": 138943,
      "duration": "5373s",
      "routeToken": "CrsCCs4BMssBGq8BCkECFg9eN0MowaEI3Y4KqMEhzOTe-Qi3947kBsb8koUBkvX0oAKJ_b1S4uPoUvzzAYfXA92t_RXyw98Up6qKAaRaABIsNBjodKMdkMYAPMLMIajCwj-zsIxpgyBxOLYjdBBeKgkO3tFDDrj4YgZB5bMaFQAATME12CCCA9MEF-kO2wL_____DyoLHgAOAHN3DggAQQEyBAUBAQM9VDgqPkV88FI_SNO81oLq4JnjYyIXcklWWFo2cjhDZmltdk9NUDQ3aU1nUU0QBRpPCk0KGAoNCgIIAREAAAAAAIBmQBF56SYxqDm4QBISCAAQAxAGEBMQEhgCQgQaAggFIhsKF3JJVlhaLWFOQnZpbXZPTVA0N2lNZ1FNcAEoASIVAACBmRY1BjeCiUQewJGTrQ3DuHRp",
      "routeLabels": [
        "DEFAULT_ROUTE"
      ]
    },
    {
      "distanceMeters": 112610,
      "duration": "7165s",
      "routeToken": "CqgCCrsBMrgBGpwBCjYCFg1SN0MowaEI3Y4KjfqjF6Ls9BXc-QGiqCOpu7FDtfCXxSG2zLOGI_r4uQGc-we_nQ7MLAASLDQY6HSjHZDGg26EAFrPI5Q3NxvGA4ELazy3sLYqno_9eAFD2KxlCqAGQeWzGg4AAMQDGwyiAqwwKQggJCoLHgBsCQ8Acm0XWWcyAgQGPVQ4Kj5FfPBSP0jikPWC95WdhIwBIhdySVZYWjZHR0RiTzV2T01QOUpiQXlBTRAFGk8KTQoYCg0KAggCEQAAAAAAAFlAEU5iEFh5af1AEhIIABADEAYQExASGAJCBBoCCAUiGwoXcklWWFo3S09Cck81dk9NUDlKYkF5QU1wASgCIhUAAIGZFlj_CmMgGE6KGZcsE-tEywM",
      "routeLabels": [
        "SHORTER_DISTANCE"
      ]
    }
  ]
}

Example request: Shorter distance and fuel efficient route

The following code shows a request for both a shorter distance route and a fuel-efficient route.

`

 curl -X POST -d '{
"origin": {  "location": {  "latLng": {  "latitude": 41.76904801292959,
"longitude": -72.67374935684933  }  }  },  "destination": {  "location": {
"latLng": {  "latitude": 41.823042361105024,  "longitude": -71.40933143059424  }
 }  },  "travelMode":"DRIVE",  "routingPreference":"TRAFFIC_AWARE_OPTIMAL",
"requestedReferenceRoutes": ["SHORTER_DISTANCE", "FUEL_EFFICIENT"] }' 
-H 'Content-Type: application/json'
-H 'X-Goog-Api-Key: YOUR_API_KEY'
-H 'X-Goog-FieldMask: routes.distanceMeters,routes.duration,routes.routeLabels,routes.routeToken'
'https://routes.googleapis.com/directions/v2:computeRoutes'

Example response: Shorter distance and Fuel-efficient route

In this case, the shorter distance and the most fuel-efficient route are the same, so that route is returned and the routeLabel is included for both types of route.

{  "routes": [  {  "distanceMeters": 138943,  "duration": "5375s",
"routeToken":
"Cr8CCs4BMssBGq8BCkECFg9eN0MowaEI3Y4KqMEhzOTe-Qi3947kBsb8koUBkvX0oAKJ_b1S4uPoUvzzAYfXA92t_RXyw98Up6qKAaRaABIsNBjodKMdkMYAPMLMIajCwj-zsIxpgyBxOLYjdBBeKgkO3tFDDrj4YgZB5bMaFQAATME12CCCA9MEF-kO2wL_____DyoLHgAOAHN3DggAQQEyBAUBAQM9VDgqPkV88FI_SNO81oLq4JnjYyIXS1laWFo4T19JcWVCM2ZFUDFMbms4UXcQBRpTClEKGAoNCgIIAREAAAAAAIBmQBFOYhBYGTy4QBIWCAAQAxAGEBMQEhgCQgQaAggFSgIIASIbChdLWVpYWjlpV0g2ZUIzZkVQMUxuazhRd3ABKAEiFQAAgZkW4Df4cspNNJZWlMZuUUxLPQ",
 "routeLabels": [  "DEFAULT_ROUTE"  ]  },  {  "distanceMeters": 112610,
"duration": "7156s",  "routeToken":
"CqwCCrsBMrgBGpwBCjYCFg1SN0MowaEI3Y4KjfqjF6Ls9BXc-QGiqCOpu7FDtfCXxSG2zLOGI_r4uQGc-we_nQ7MLAASLDQY6HSjHZDGg26EAFrPI5Q3NxvGA4ELazy3sLYqno_9eAFD2KxlCqAGQeWzGg4AAMQDGwyiAqwwKQggJCoLHgBsCQ8Acm0XWWcyAgQGPVQ4Kj5FfPBSP0jikPWC95WdhIwBIhdLWVpYWi1UNklfT055OVlQczhhcWlRSRAFGlMKUQoYCg0KAggCEQAAAAAAAFlAEU5iEFh5af1AEhYIABADEAYQExASGAJCBBoCCAVKAggBIhsKF0tZWlhaNERXSF9PTnk5WVBzOGFxaVFJcAEoAiIVAACBmRaESp2EJS5nmwiEF8KH15_f",
 "routeLabels": [  "FUEL_EFFICIENT",  "SHORTER_DISTANCE"  ]  }  ] }

Supported regions

Shorter distance routes are supported in all regions.

Billing

Google Maps Platform does not charge extra for the use of an experimental feature. You will be charged based on your usage of the API based on other parameters you set.

Learn more about billing for the Routes API.