Routes Preferred API 目前僅適用於特定客戶。如需瞭解詳情,請
聯絡銷售人員。
Method: computeRouteMatrix
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
擷取起點與目的地清單,並傳回包含路線資訊的串流,每個起點和目的地組合都會包含路線資訊。
注意:這個方法需要您在輸入內容中指定回應欄位遮罩。您可以使用網址參數 $fields
或 fields
,或是使用 HTTP/gRPC 標頭 X-Goog-FieldMask
提供回應欄位遮罩 (請參閱可用的網址參數和標頭)。值為以半形逗號分隔的欄位路徑清單。請參閱這份詳細說明文件,瞭解如何建構欄位路徑。
舉例來說,在這個方法中:
- 所有可用欄位的欄位遮罩 (供手動檢查):
X-Goog-FieldMask: *
- 路線時間長度、距離、元素狀態、條件和元素索引的欄位遮罩 (正式版設定範例):
X-Goog-FieldMask:
originIndex,destinationIndex,status,condition,distanceMeters,duration
請務必在欄位遮罩中加入 status
,否則所有郵件看起來都會正常。Google 不建議使用萬用字元 (*
) 回應欄位遮罩,因為:
- 只選取您需要的欄位有助於我們的伺服器節省運算週期,讓我們以更短的延遲時間將結果傳回給您。
- 只選取實際工作中所需的欄位,即可確保延遲時間穩定。我們日後可能會新增更多回應欄位,而這些新欄位可能需要額外的運算時間。如果您選取所有欄位,或是選取頂層的所有欄位,則可能會出現成效降低的情況,因為我們新增的所有欄位都會自動納入回應中。
- 如果只選取您需要的欄位,回應大小會縮減,網路處理量也會因此增加。
HTTP 要求
POST https://routespreferred.googleapis.com/v1alpha:computeRouteMatrix
這個網址使用 gRPC 轉碼語法。
要求主體
要求主體的資料會採用以下結構:
欄位 |
origins[] |
object (RouteMatrixOrigin )
必要欄位。來源陣列,用於決定回應矩陣的資料列。來源和目的地的基數有幾項大小限制:
- 元素數量 (出發地 × 目的地) 不得超過 625 個。
- 如果將 routePreference 設為
TRAFFIC_AWARE_OPTIMAL ,元素 (起點 × 目的地) 數不得超過 100。
- 以
placeId 指定的路線控點 (出發地 + 目的地) 數量不得超過 50 個。
|
destinations[] |
object (RouteMatrixDestination )
必要欄位。目的地陣列,用於決定回應矩陣的資料欄。
|
travelMode |
enum (RouteTravelMode )
選用設定。指定交通方式。
|
routingPreference |
enum (RoutingPreference )
選用設定。指定計算路線的方式。伺服器會嘗試使用所選的路由偏好設定來計算路徑。如果路由偏好設定導致錯誤或延遲時間過長,系統會傳回錯誤。只有在 travelMode 為 DRIVE 或 TWO_WHEELER 時,才能指定這個選項,否則要求會失敗。
|
departureTime |
string (Timestamp format)
選用設定。出發時間。如果您未設定這個值,系統會預設為您提出要求的時間。如果您將這個值設為已發生的時間,要求就會失敗。 RFC3339 世界標準時間「Zulu」格式的時間戳記,精確度達奈秒單位,最多九個小數位數。範例:"2014-10-02T15:01:23Z" 和 "2014-10-02T15:01:23.045123456Z" 。
|
回應主體
如果成功,回應主體會包含 RouteMatrixElement
執行個體的串流。
授權範圍
需要下列 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\u003eTakes a list of origins and destinations, returning route information for each combination.\u003c/p\u003e\n"],["\u003cp\u003eRequires specifying a response field mask for optimized performance and data selection.\u003c/p\u003e\n"],["\u003cp\u003eAccepts parameters for travel mode, routing preference, and departure time.\u003c/p\u003e\n"],["\u003cp\u003eReturns a stream of \u003ccode\u003eRouteMatrixElement\u003c/code\u003e instances containing route details.\u003c/p\u003e\n"],["\u003cp\u003eRequires the \u003ccode\u003ehttps://www.googleapis.com/auth/maps-platform.routespreferred\u003c/code\u003e OAuth scope for authorization.\u003c/p\u003e\n"]]],["This method computes route information for multiple origin-destination pairs. It requires a `POST` request to `computeRouteMatrix` with lists of `origins` and `destinations` in the request body. A field mask must be included to specify which data fields to return, with `status` being critical. Optional parameters include `travelMode`, `routingPreference`, and `departureTime`. The response is a stream of `RouteMatrixElement` instances, and the method requires a specific OAuth scope for authorization.\n"],null,[]]