从预览版中迁移
Routes API 于 2022 年 9 月以公开预览版(正式版之前)的形式发布。正式发布前的产品或功能受 Google Maps Platform 服务专用条款约束。如需了解详情,请参阅发布阶段说明。
本部分介绍了如何将应用从预览版迁移到 GA 版。
向正式版添加的新功能
正式版中新增了以下预览版中未包含的新功能:
除了地点 ID 和纬度/经度坐标之外,您现在还可以在 GA 版中使用以下方式指定位置:
地址字符串(“伊利诺伊州芝加哥市”或“澳大利亚北领地达尔文市”)
用户通常通过地址字符串输入地址。不过,{product_name} 必须先在内部对地址字符串进行地理编码,将其转换为纬度/经度坐标,然后才能计算路线。
此外,还添加了对 regionCode
请求参数的支持,可让您指定返回特定地理区域的地理编码结果。
Plus 代码
Plus Code 就像没有实际地址的人员或地点的街道地址。Plus Code 以经纬度为依据,以数字和字母的形式显示,而不是包含街道名称和门牌号的地址。
计算路线响应现在包含 geocodingResults
数组。对于请求中以地址字符串或 Plus 代码指定的每个位置(起点、终点或中间航点),该 API 都会执行地点 ID 查找。此数组的每个元素都包含与相应地点对应的地点 ID,以及与相应地点相关的其他元数据。系统会忽略请求中以地点 ID 或纬度/经度坐标指定的位置。
现有预览版功能的变化
现在,您必须向请求中添加新的数组 extraComputations
字段,以便在 GA 中显式启用以下功能:
在预览版中,您使用了字段掩码来指定在响应中返回这些地图项的信息。现在,您必须同时满足以下条件:
- 设置新的
extraComputations
数组请求参数即可启用这些功能。
- 设置字段掩码,以指定要在响应中返回信息。
我需要注意什么?
除非通过设置 extraComputations
明确启用,否则以下字段将不再包含在 computeRouteMatrix 响应中:
travelAdvisory.tollInfo
(过路费信息)
除非通过设置 extraComputations
明确启用,否则以下字段将不再包含在 computeRoutes 响应中:
routes.legs.travelAdvisory.tollInfo
(过路费信息)
routes.travelAdvisory.tollInfo
(过路费信息)
routes.travelAdvisory.fuelConsumptionMicroliters
(燃油消耗)
routes.travelAdvisory.speedReadingIntervals
(多段线上的交通信息)
routes.legs.travelAdvisory.speedReadingIntervals
(多段线上的交通信息)
我需要做什么?
如需接收多段线的过路费信息、油耗或路况响应字段,您必须将新的请求数组字段 extraComputations
设置为包含以下一个或多个值:
如需接收过路费信息,请将新的 extraComputations
数组字段设置为 "TOLLS"
。
如需接收油耗,请将新的 extraComputations
数组字段设置为 "FUEL_CONSUMPTION"
。
如需接收多段线的路况信息,请将新的 extraComputations
数组字段设置为 "TRAFFIC_ON_POLYLINE"
。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-03-20。
[null,null,["最后更新时间 (UTC):2025-03-20。"],[[["The Routes API has transitioned from Preview to General Availability (GA), introducing new features and changes to existing ones."],["You can now specify locations using address strings and Plus Codes in addition to place IDs and coordinates."],["Toll info, fuel consumption, and traffic on a polyline now require explicit enablement using the `extraComputations` field in requests."],["The `geocodingResults` array has been added to the response, providing place IDs and metadata for locations specified as address strings or Plus Codes."],["Existing implementations relying on implicit inclusion of toll info, fuel consumption, or traffic on a polyline data need to be updated to utilize the `extraComputations` field."]]],["The Routes API's GA release introduces new location specification options, including address strings and Plus Codes, and includes a `geocodingResults` array in the response. To enable toll info, fuel consumption, and traffic on a polyline, users must now set the `extraComputations` array in their requests. `extraComputations` values are \"TOLLS\", \"FUEL_CONSUMPTION\", and \"TRAFFIC_ON_POLYLINE\". The field mask must still be used. Certain fields will be omitted in the response unless enabled by `extraComputations`.\n"]]