Routes Preferred API 目前僅適用於特定客戶。如需瞭解詳情,請
聯絡銷售人員。
Method: computeCustomRoutes
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
在提供一組終點和中途路標及路線目標的情況下,計算路線目標的最佳路線。系統也會傳回最快路線和最短路線做為參考路線。
注意:這個方法需要您在輸入中指定回應欄位遮罩。如要提供回應欄位遮罩,您可以使用網址參數 $fields
或 fields
,或使用 HTTP/gRPC 標頭 X-Goog-FieldMask
(請參閱可用的網址參數和標頭)。值為以半形逗號分隔的欄位路徑清單。請參閱這份詳細說明文件,瞭解如何建構欄位路徑。
例如,在這個方法中:
- 所有可用欄位的欄位遮罩 (供手動檢查):
X-Goog-FieldMask: *
- 路線距離、時間長度、符記和通行費資訊的欄位遮罩:
X-Goog-FieldMask:
routes.route.distanceMeters,routes.route.duration,routes.token,routes.route.travelAdvisory.tollInfo
Google 不建議您使用萬用字元 (*
) 回應欄位遮罩,或是在頂層 (routes
) 指定欄位遮罩,原因如下:
- 只選取所需欄位有助於伺服器節省運算週期,讓我們能以更低的延遲時間傳回結果。
- 僅選取實際工作環境工作中所需的欄位,可確保延遲時間保持穩定。我們日後可能會新增更多回應欄位,而這些新欄位可能需要額外的運算時間。如果您選取所有欄位,或是選取頂層的所有欄位,系統會自動將新增的任何欄位納入回應,因此可能會導致效能降低。
- 只選取所需欄位,可縮小回應大小,進而提高網路傳輸量。
HTTP 要求
POST https://routespreferred.googleapis.com/v1alpha:computeCustomRoutes
這個網址使用 gRPC 轉碼語法。
要求主體
要求主體的資料會採用以下結構:
JSON 表示法 |
{
"origin": {
object (Waypoint )
},
"destination": {
object (Waypoint )
},
"intermediates": [
{
object (Waypoint )
}
],
"travelMode": enum (RouteTravelMode ),
"routingPreference": enum (RoutingPreference ),
"polylineQuality": enum (PolylineQuality ),
"polylineEncoding": enum (PolylineEncoding ),
"departureTime": string,
"routeModifiers": {
object (RouteModifiers )
},
"routeObjective": {
object (RouteObjective )
},
"languageCode": string,
"units": enum (Units )
} |
欄位 |
origin |
object (Waypoint )
必要欄位。來源路線控點。
|
destination |
object (Waypoint )
必要欄位。目的地路線控點。
|
intermediates[] |
object (Waypoint )
選用設定。沿路 (不含終點) 的路線控點組合,用於停靠或經過。最多支援 25 個中繼路線控點。
|
travelMode |
enum (RouteTravelMode )
選用設定。指定交通方式,系統僅支援 DRIVE 和「TWO_WHEELER」。
|
routingPreference |
enum (RoutingPreference )
選用設定。指定如何計算路徑。伺服器會嘗試使用所選的路由偏好設定來計算路徑。如果轉送偏好設定導致錯誤或過長的延遲時間,則會傳回錯誤。只有在 travelMode 為 DRIVE 或 TWO_WHEELER 時,您才能指定此選項,否則要求會失敗。
|
polylineQuality |
enum (PolylineQuality )
選用設定。指定您對折線品質的偏好設定。
|
polylineEncoding |
enum (PolylineEncoding )
選用設定。指定折線的偏好編碼。
|
departureTime |
string (Timestamp format)
選用設定。出發時間。如未設定這個值,則這個值會預設為您提出要求的時間。如果將這個值設為已發生的時間,要求就會失敗。 RFC3339 世界標準時間「Zulu」格式的時間戳記,精確度達奈秒單位,最多九個小數位數。例如 "2014-10-02T15:01:23Z" 和 "2014-10-02T15:01:23.045123456Z" 。
|
routeModifiers |
object (RouteModifiers )
選用設定。一組滿足條件,這些條件會影響路線的計算方式。
|
routeObjective |
object (RouteObjective )
必要欄位。要進行最佳化調整的路線目標。
|
languageCode |
string
選用設定。BCP-47 語言代碼,例如「en-US」或「sr-Latn」。詳情請參閱 Unicode 語言代碼 ID。如需支援的語言清單,請參閱語言支援。如果您未提供這個值,系統會根據路線要求的位置推測顯示語言。
|
units |
enum (Units )
選用設定。指定顯示欄位的測量單位。這包括 NavigationInstruction 中的 instruction 欄位。路線、路段、步行距離和時間的度量單位不會受到這個值的影響。如未提供這個值,系統會根據要求的位置推斷顯示單位。
|
授權範圍
需要下列 OAuth 範圍:
https://www.googleapis.com/auth/maps-platform.routespreferred
詳情請參閱 OAuth 2.0 總覽。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-08-29 (世界標準時間)。
[[["容易理解","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"]],["上次更新時間:2025-08-29 (世界標準時間)。"],[[["\u003cp\u003eGiven terminal and intermediate waypoints, and a route objective, this method computes the best route, also returning the fastest and shortest routes for reference.\u003c/p\u003e\n"],["\u003cp\u003eRequests require specifying a response field mask for optimized performance and to manage response size.\u003c/p\u003e\n"],["\u003cp\u003eThe request body includes origin, destination, intermediates, travel mode, routing preferences, and other route-specific parameters.\u003c/p\u003e\n"],["\u003cp\u003eSuccessful responses contain a \u003ccode\u003eComputeCustomRoutesResponse\u003c/code\u003e object with the calculated routes.\u003c/p\u003e\n"],["\u003cp\u003eAuthorization requires the \u003ccode\u003ehttps://www.googleapis.com/auth/maps-platform.routespreferred\u003c/code\u003e scope.\u003c/p\u003e\n"]]],["This document outlines a method to compute the best route based on a given objective, along with the fastest and shortest routes as references. It requires a POST HTTP request to `https://routespreferred.googleapis.com/v1alpha:computeCustomRoutes` with a JSON request body. The request body requires the origin, destination, and route objective. It can also include intermediate waypoints, travel mode, routing preference, and other optional parameters. The response provides a `ComputeCustomRoutesResponse`, and the method needs the `https://www.googleapis.com/auth/maps-platform.routespreferred` authorization scope. It is recommended to specify a field mask to limit the response size and improve latency.\n"],null,[]]