Try the next generation of Distance Matrix features with the
Routes API .
Send feedback
Get started with the Distance Matrix API
Stay organized with collections
Save and categorize content based on your preferences.
Sample request and response
This example requests the distance matrix data between Washington, DC and
New York City, NY, in JSON format:
URL
https://maps.googleapis.com/maps/api/distancematrix/json
?destinations=New%20York%20City%2C%20NY
&origins=Washington%2C%20DC
&units=imperial
&key=YOUR_API_KEY
cURL
curl -L -X GET 'https://maps.googleapis.com/maps/api/distancematrix/json?origins= Washington%2C%20DC&destinations= New%20York%20City%2C%20NY&units= imperial&key = YOUR_API_KEY'
Try it! Test this request by entering the URL into your web browser - be sure
to replace YOUR_API_KEY
with your actual API key .
The response shows the distance and duration between the specified origins
and destinations.
Learn how to build request URLs ,
including all available parameters.
This code sample is in JSON and XML formats:
JSON
{
"des t i nat io n _addresses ": [ "New York , NY , USA "],
"origi n _addresses ": [ "Washi n g t o n , DC , USA "],
"rows ":
[
{
"eleme nts ":
[
{
"dis tan ce ": { "te x t ": "228 mi ", "value ": 367654 },
"dura t io n ": { "te x t ": "3 hours 55 mi ns ", "value ": 14078 },
"s tatus ": "OK ",
},
],
},
],
"s tatus ": "OK ",
}
XML
<DistanceMatrixResponse>
<status>OK</status>
<origin_address>Washington, DC, USA</origin_address>
<destination_address>New York, NY, USA</destination_address>
<row>
<element>
<status>OK</status>
<duration>
<value>14078</value>
<text>3 hours 55 mins</text>
</duration>
<distance>
<value>367654</value>
<text>228 mi</text>
</distance>
</element>
</row>
</DistanceMatrixResponse>
Check the developer's guide to understand the response .
Send feedback
Except 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 2024-10-01 UTC.
[{
"type": "thumb-down",
"id": "missingTheInformationINeed",
"label":"Missing the information I need"
},{
"type": "thumb-down",
"id": "tooComplicatedTooManySteps",
"label":"Too complicated / too many steps"
},{
"type": "thumb-down",
"id": "outOfDate",
"label":"Out of date"
},{
"type": "thumb-down",
"id": "samplesCodeIssue",
"label":"Samples / code issue"
},{
"type": "thumb-down",
"id": "otherDown",
"label":"Other"
}]
[{
"type": "thumb-up",
"id": "easyToUnderstand",
"label":"Easy to understand"
},{
"type": "thumb-up",
"id": "solvedMyProblem",
"label":"Solved my problem"
},{
"type": "thumb-up",
"id": "otherUp",
"label":"Other"
}]
Need to tell us more?
{"lastModified": "Last updated 2024-10-01 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 2024-10-01 UTC."]]