Stay organized with collections Save and categorize content based on your preferences.
IntroductionThe Distance Matrix API (Legacy) 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.
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.
This API is now in legacy mode. Use Compute Route Matrix instead. What you can do with the Distance Matrix APIWith 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:
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:
The following example shows a request for two origins: Washington, DC and Boston, with a single destination, New York City, NY, in JSON format:
https://maps.googleapis.com/maps/api/distancematrix/json ?destinations=New%20York%20City%2C%20NY &origins=Washington%2C%20DC%7CBoston &units=imperial &key=YOUR_API_KEYResources
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 matrixSupply origins and destinations in the form of place IDs, addresses, or latitude/longitude coordinates.
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 nextExcept as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-08-14 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-14 UTC."],[[["The Distance Matrix API calculates travel distance and time between multiple origins and destinations, supporting various modes of transport like driving, biking, transit, or walking."],["This API is ideal for optimizing logistics, such as determining efficient delivery routes or assigning workers to job sites based on travel time and distance."],["The API returns data in JSON or XML format, providing distance and duration information for each origin-destination pair, including traffic estimations for driving mode."],["While it doesn't provide turn-by-turn directions, you can use the Directions API for detailed route guidance between a single origin and destination."],["You can access the Distance Matrix API using client libraries for Java, Python, Go, and Node.js, allowing integration with your applications for custom solutions."]]],["The Distance Matrix API calculates travel distance and duration between multiple origins and destinations for various transport modes like driving, biking, transit, or walking. It takes an HTTPS request specifying origins and destinations and returns data for each origin-destination pair, in a step-wise fashion. Users can customize requests with parameters like transport mode, units, and departure times, to be used for travel efficiency. The service can return distance, and estimated travel time, including traffic conditions. It supports JSON and XML return format.\n"]]
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4