Distance Matrix API overview

The Distance Matrix API is a service that accepts an HTTPS request containing origins and destinations for a given mode of transport. For each combination of origin and destination, it returns travel distance and duration.

Why use the Distance Matrix API

You can use the Distance Matrix API to help determine the most efficient travel routes between multiple possible origins and destinations. For example, which workers to send to job sites, or from which warehouses to send packages.

What can you do with the Distance Matrix API

With the Distance Matrix API, you can provide travel distance and time for a matrix of origins and destinations. You can specify several options, including mode of transportation, such as driving, biking, transit or walking, as well as transit modes, such as bus, subway, train, tram, or rail.

The Distance Matrix API provides information based on the recommended route between start and end points. You can request these kinds of distance data:

  • Distance for a selected travel mode
  • Distance in kilometers or miles
  • Estimated travel time in traffic

map showing origin and destinations on a map and in the API response

How the Distance Matrix API works

The Distance Matrix API uses any number of origins (starting points) and destinations, and returns the distance and travel time between each origin and all requested destinations, starting with the first origin in the request and proceeding step-wise to the next.

For example, if your request specifies A and B as origins, and C and D as destinations, it returns distances and travel time in this order:

  • A to C
  • A to D
  • B to C
  • B to D

The following example shows a request for two origins: Washington, DC and Boston, with a single destination, New York City, NY, in JSON format:



The following table summarizes the resources available through the Distance Matrix API along with the data it returns.

Data resources Data returned Return format
Distance matrix

Supply origins and destinations in the form of place IDs, addresses, or latitude/longitude coordinates.

  • Distance and travel time between each origin and each destination
  • Duration in traffic if you've specified the driving mode and a departure time
  • JSON
  • XML

How to use the Distance Matrix API

1 Get set up. Start with Set up your Google Cloud project and complete the setup instructions that follow.
2 Try a distance matrix request Once you have an API key, you can start testing out the Distance Matrix API directly from your browser. See Sample requests in the Get started guide for examples.
3 Compose a more complex request Try a request that supplies multiple origins and destinations. Learn about optional parameters to constrain calculations, such as a specified departure time, or route restrictions. See Optional parameters in the Distance Matrix request and response guide.
4 Understand response basics Explore the data responses to prepare to use distance matrix data for your app. See Distance matrix responses for details.
5 Incorporate distance matrix data into your own app! You can use this data to calculate travel distance and time.

Available client libraries

Call this API in the language of your choice through one of the following client libraries:

The Java Client, Python Client, Go Client and Node.js Client for Google Maps Services are community-supported client libraries, open sourced under the Apache 2.0 License. Download them from GitHub, where you can also find installation instructions and sample code.

What's next