從預覽版本遷移
Routes API 已於 2022 年 9 月推出公開預先發布版 (GA 前)。正式發布前產品/功能受到《Google 地圖平台服務專屬條款》規範。詳情請參閱推出階段說明。
本節說明如何將應用程式從預覽版遷移至 GA 版本。
在 GA 版本中新增功能
GA 版本新增了以下預覽版未包含的新功能:
除了地點 ID 和經緯度座標外,您現在也可以使用以下方式,在 GA 版本中指定位置:
地址字串 (「伊利諾州芝加哥」或「澳洲新南威爾斯州達爾文」)
使用者通常會輸入地址字串。不過,{product_name} 必須先在內部將地址字串地理編碼,將其轉換為經緯度座標,才能計算路線。
此外,我們也新增了對 regionCode
要求參數的支援,讓您指定要傳回特定地理區域的地理編碼結果。
Plus Codes
對於沒有實際地址的人物或地點,Plus Code 就類似街道地址。與街道名稱和門牌號碼不同,Plus Code 是以經緯度為依據,並以數字和英文字母顯示。
compute routes response 現在包含 geocodingResults
陣列。針對要求中每個以地址字串或Plus Code指定的位置 (原點、目的地或中繼路標),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"
。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-02-06 (世界標準時間)。
[null,null,["上次更新時間:2025-02-06 (世界標準時間)。"],[[["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"]]