发送反馈
Distance Matrix API 使用入门
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
示例请求和响应
此示例请求华盛顿特区和
纽约州纽约市,采用 JSON 格式:
网址
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'
试试看! 通过在网络浏览器中输入网址来测试此请求 - 确保
将 YOUR_API_KEY
替换为您的实际 API 密钥 。
响应会显示指定起点之间的距离和时长
和目的地。
了解如何构建请求网址 。
包括所有可用的参数。
此代码示例采用 JSON 和 XML 格式:
JSON
{
"destination_addresses": ["New York, NY, USA"],
"origin_addresses": ["Washington, DC, USA"],
"rows":
[
{
"elements":
[
{
"distance": { "text": "228 mi", "value": 367654 },
"duration": { "text": "3 hours 55 mins", "value": 14078 },
"status": "OK",
},
],
},
],
"status": "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>
请参阅开发者指南,了解回复 。
发送反馈
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可 获得了许可,并且代码示例已根据 Apache 2.0 许可 获得了许可。有关详情,请参阅 Google 开发者网站政策 。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2024-09-05。
[{
"type": "thumb-down",
"id": "missingTheInformationINeed",
"label":"没有我需要的信息"
},{
"type": "thumb-down",
"id": "tooComplicatedTooManySteps",
"label":"太复杂/步骤太多"
},{
"type": "thumb-down",
"id": "outOfDate",
"label":"内容需要更新"
},{
"type": "thumb-down",
"id": "translationIssue",
"label":"翻译问题"
},{
"type": "thumb-down",
"id": "samplesCodeIssue",
"label":"示例/代码问题"
},{
"type": "thumb-down",
"id": "otherDown",
"label":"其他"
}]
[{
"type": "thumb-up",
"id": "easyToUnderstand",
"label":"易于理解"
},{
"type": "thumb-up",
"id": "solvedMyProblem",
"label":"解决了我的问题"
},{
"type": "thumb-up",
"id": "otherUp",
"label":"其他"
}]
需要向我们提供更多信息?
{"lastModified": "\u6700\u540e\u66f4\u65b0\u65f6\u95f4 (UTC)\uff1a2024-09-05\u3002"}
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["没有我需要的信息","missingTheInformationINeed","thumb-down"],["太复杂/步骤太多","tooComplicatedTooManySteps","thumb-down"],["内容需要更新","outOfDate","thumb-down"],["翻译问题","translationIssue","thumb-down"],["示例/代码问题","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2024-09-05。"]]