It's the 15th anniversary of Google Maps Platform - Check out the latest news and announcements

Get Started

The Distance Matrix API is a service that provides travel distance and time for a matrix of origins and destinations, based on the recommended route between start and end points.

Sample request and response

Access the Distance Matrix API through an HTTP interface, with requests constructed as a URL string, using origins and destinations, along with your API key.

The following example requests the distance matrix data between Washington, DC and New York City, NY, in JSON format:

https://maps.googleapis.com/maps/api/distancematrix/json?units=imperial&origins=Washington,DC&destinations=New+York+City,NY&key=YOUR_API_KEY

Try it! You can test this by entering the URL into your web browser (be sure to replace YOUR_API_KEY with your actual API key). The response includes the distance and duration between the specified origins and destinations.

View the developer's guide for more information about building request URLs and available parameters and understanding the response.

Below is a sample response, in JSON:

{
   "destination_addresses" : [ "New York, NY, USA" ],
   "origin_addresses" : [ "Washington, DC, USA" ],
   "rows" : [
      {
         "elements" : [
            {
               "distance" : {
                  "text" : "225 mi",
                  "value" : 361715
               },
               "duration" : {
                  "text" : "3 hours 49 mins",
                  "value" : 13725
               },
               "status" : "OK"
            }
         ]
      }
   ],
   "status" : "OK"
}

Start coding with our client libraries

Client libraries make developing with the Google Maps web service APIs easier by providing simple, native implementations of common tasks, such as authentication, request throttling and automatic retry. The Distance Matrix API is available in the Java Client, Python Client, Go Client and Node.js Client for Google Maps Services.

Authentication, quotas, pricing, and policies

Authentication

To use the Distance Matrix API, you must first enable the API and obtain the proper authentication credentials. For more information, see Get Started with Google Maps Platform.

Quotas and pricing

Review the usage and billing page for details on the quotas and pricing set for the Distance Matrix API.

Policies

Use of the Distance Matrix API must be in accordance with the API policies.

Learn more

There’s more you can do with the Distance Matrix API, like requesting distance data for different travel modes, requesting distance data in different units (for example, kilometers or miles), and estimating travel time in traffic. See the Distance Matrix API developer guide for more examples and other details.

The Distance Matrix API developer guide is intended for developers who wish to compute travel distance and time between a number of points within maps provided by one of the Google Maps APIs. It provides an introduction to using the API and reference material on the available parameters.