Method: computeRoutes

Returns the primary route between requested origin and destination for the requested travel mode.

HTTP request

POST https://mapstools.googleapis.com/v1:computeRoutes

The URL uses gRPC Transcoding syntax.

Request body

The request body contains data with the following structure:

JSON representation
{
  "origin": {
    object (Waypoint)
  },
  "destination": {
    object (Waypoint)
  },
  "travelMode": enum (RouteTravelMode),
  "intermediateWaypoints": [
    {
      object (Waypoint)
    }
  ],
  "routingPreference": enum (RoutingPreference),
  "locationBias": {
    object (LatLng)
  },
  "includePolyline": boolean,
  "computeAlternativeRoutes": boolean,

  // The following is a list of mutually exclusive fields. At most one of the
  // fields will be set in a response:
  "departureTime": string,
  "arrivalTime": string
  // End of mutually exclusive fields.
}
Fields
origin

object (Waypoint)

Required. Origin waypoint.

destination

object (Waypoint)

Required. Destination waypoint.

travelMode

enum (RouteTravelMode)

Optional. Specifies the mode of transportation.

intermediateWaypoints[]

object (Waypoint)

Optional. Intermediate stops between the origin and destination to pass through in order. Up to 25 intermediate waypoints are supported.

Specifying more than 10 intermediate waypoints will incur higher cost and higher latency. Intermediate waypoints are not supported when travelMode is TRANSIT.

routingPreference

enum (RoutingPreference)

Optional. Determines how traffic data is used to compute the route. ROUTING_PREFERENCE_TRAFFIC_AWARE_OPTIMAL is not supported when travelMode is WALK or BICYCLE. For TRANSIT, it enables realtime transit data, such as delays and cancellations.

locationBias

object (LatLng)

Optional. A location to bias the search results toward, for example to disambiguate waypoint text queries.

includePolyline

boolean

Optional. Whether to include the encoded polyline in the response routes. Defaults to false. When set to true, Route.encoded_polyline is returned.

computeAlternativeRoutes

boolean

Optional. Whether to compute alternative routes in addition to the recommended route. Defaults to false, in which case only the recommended route is returned. When set to true, up to all available routes are returned, though alternatives may not be available for every request.

Specifies when to depart from the origin or arrive at the final waypoint. Defaults to departing at the current time if not specified. For TRANSIT, the time must be at most 7 days in the past and at most 100 days in the future. For other travel modes, the time must not be in the past and must be at most 365 days in the future. The following is a list of mutually exclusive fields. At most one of the fields will be set in a response:
departureTime

string (Timestamp format)

Optional. Indicates that the route should be computed based on departure time.

Uses RFC 3339, where generated output will always be Z-normalized and use 0, 3, 6 or 9 fractional digits. Offsets other than "Z" are also accepted. Examples: "2014-10-02T15:01:23Z", "2014-10-02T15:01:23.045123456Z" or "2014-10-02T15:01:23+05:30".

arrivalTime

string (Timestamp format)

Optional. Indicates that the route should be computed based on arrival time.

Uses RFC 3339, where generated output will always be Z-normalized and use 0, 3, 6 or 9 fractional digits. Offsets other than "Z" are also accepted. Examples: "2014-10-02T15:01:23Z", "2014-10-02T15:01:23.045123456Z" or "2014-10-02T15:01:23+05:30".

End of mutually exclusive fields.

Response body

If successful, the response body contains an instance of ComputeRoutesResponse.

Authorization scopes

Requires the following OAuth scope:

  • https://www.googleapis.com/auth/maps-platform.mapstools