The Google Maps 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.
This service is also available as part of the client-side Google Maps JavaScript API, or for server-side use with the Java Client, Python Client, Go Client and Node.js Client for Google Maps Services.
Sample request and response
You access the Google Maps 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 Google Maps Distance Matrix API is available in the Java Client, Python Client, Go Client and Node.js Client for Google Maps Services.
Authentication, quotas, and policies
Activate the API and get an API key
To use the Google Maps Distance Matrix API, you must first activate the API in the Google API Console and obtain the proper authentication credentials. You need to provide an API key in each request (or a client ID if you have a Premium Plan).
Click the button below to flow through a process where you will:
- Create or select a project
- Enable the API
- Get an API key
Learn more about authentication credentials.
Quotas
Review the usage limits page for details on the quotas set for the Google Maps Distance Matrix API.
Policies
Use of the Google Maps 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’s guide for more examples and other details.
