The Distance Matrix API provides travel distance and time for a matrix of origins
and destinations, and consists of rows containing duration
and distance
values
for each pair. Distance Matrix is available in several forms:
- as a standalone API
- as part of the client-side Maps JavaScript API
- for server-side use as part of the Client Libraries for Google Maps Web Services
What can you do with the Distance Matrix API?
The API returns information based on the recommended route between start and end points. You can request distance data for different travel modes, request distance data in different units such kilometers or miles, and estimate travel time in traffic.
For more examples, see the Distance Matrix API developer guide, which provides an introduction to using the API and reference material on the available parameters.
Why use Distance Matrix?
Use the Distance Matrix API when your solution requires distance and travel time between a large list of origin-destination points.
If you want to use Distance Matrix functionality and get serialization of requests and deserialization of responses, automatic retries, and some client validation of requests, try one of our client libraries. If you're already using the Maps JavaScript API, use the Distance Matrix service to get the Distance Matrix API's functionality.
How to use Distance Matrix
Access the Distance Matrix API through an HTTP interface, with requests constructed as a URL string, passing origins and destinations, along with your API key.
- If you want to use one of our client libraries instead of the standalone Distance Matrix API or the client-side web service, download and install it. Learn about our client libraries.
- Choose or create a project, enable billing, and enable the Distance Matrix API. See Set up in the Cloud Console.
- Create and restrict an API key, and add it to your code. See Use an API Key.
- View a Distance Matrix request and response and try a sample request.
Recommended content
- Client libraries - use one of our client libraries, which include the functionality of several APIs including the Distance Matrix.
- Web service best practices - learn several best practices for using and working with the Distance Matrix.
- Release notes - see the release notes for the Distance Matrix.
- Quota and billing information - find the billing units and costs for the Distance Matrix.
- Policies and restrictions - understand the restrictions on using the Distance Matrix.