This product or feature is in Legacy status. For more information about the Legacy stage and how to migrate from Legacy to newer services, see
Legacy products and features.
Google uses AI technology to translate content into your preferred language. AI translations can contain errors.
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
OK
Washington, DC, USA
New York, NY, USA
OK
14078
3 hours 55 mins
367654
228 mi
查看开发者指南,了解响应。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2026-06-19。
[null,null,["最后更新时间 (UTC):2026-06-19。"],[],["The content demonstrates requesting distance data between Washington, DC, and New York City using the Google Maps Distance Matrix API. The request URL and cURL command are provided, requiring the user to replace `YOUR_API_KEY` with their own. The API returns distance (228 mi) and duration (3 hours 55 mins) data in both JSON and XML formats. Users can test the URL and further understand responses, and can learn to build custom URL requests through provided documentation.\n"]]