Compute Routes Overview

Compute Routes is a method in the Routes API service that accepts an HTTPS request and returns the ideal route between two locations. Provide directions with real-time traffic for transit, biking, driving, 2-wheel motorized vehicles, or walking between multiple locations.

Need Route Matrixes? If you are interested in a route matrix, see Compute Route Matrix Overview.

Migrating? If you are migrating from the Distance Matrix API (Legacy), see migration instructions starting with Why migrate to the Routes API.

Why use Compute Routes

With Compute Routes, with a wide range of route details you can route your vehicles or packages according to your preferences while optimizing for cost and quality.

What you can do with Compute Routes?

With the Routes API Compute Routes method, you can do the following things:

  • Get directions for different ways to travel, and for a single or multiple destinations:

    • Modes of transportation: transit, driving, two-wheel vehicles, walking, or bicycling.

    • A series of waypoints that you can optimize for the most efficient order in which to travel to them.

  • Use multiple ways to specify origins, destinations, and waypoints:

    • Text strings. For example: "Chicago, IL", "Darwin, NT, Australia", "1800 Amphitheatre Parkway, Mountain View, CA 94043", or "CWF6+FWX Mountain View, California"

    • Place IDs

    • Latitude and longitude coordinates, optionally with vehicle heading

  • Fine-tune your route options based on your needs and goals:

  • Control your latency and quality by requesting only the data you need using a field mask, which helps you avoid unnecessary processing time and higher request billing rates. For details, see Choose what information to return.

How Compute Routes works

The Routes API ComputeRoutes method accepts an HTTP POST request with a JSON request body that contains the request details. Required are an origin, destination, travelMode, and a field mask to specify which fields to return.

Example

curl -X POST -d '{
    "origin": {
      "address": "1800 Amphitheatre Parkway, Mountain View, CA 94043"
    },
    "destination": {
      "address": "Sloat Blvd &, Upper Great Hwy, San Francisco, CA 94132"
    },
  "travelMode": "DRIVE"
  }' \
  -H 'Content-Type: application/json' -H 'X-Goog-Api-Key: YOUR_API_KEY' \
  -H 'X-Goog-FieldMask: routes.duration,routes.distanceMeters' \
  'https://routes.googleapis.com/directions/v2:computeRoutes'

The service then calculates the requested route, and returns the fields you've requested.

Resources

The following table summarizes the resources available through the Routes API Compute Routes method, along with the data it returns.

Data resources Data returned Return format
ComputeRoutes Returns routes, legs, and steps for a route, with alternate routes, if requested. JSON

How to use Compute Routes

1 Get set up Start with Set up your Google Cloud project and complete the setup instructions that follow.
2 Understand how the Routes API bills For information, see Usage and billing.
3 Compute a route and review the response For more information, see Get a route and Review the route responses.

Available client libraries

For a list of the available client libraries for Compute Routes, see Client libraries.

What's next