Routes Preferred API 目前僅適用於特定客戶。如需瞭解詳情,請
聯絡銷售人員。
選擇要傳回的欄位
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
呼叫 ComputeRoutes()
方法時,您必須指定要傳回回應中的哪些欄位。您可以使用回應欄位遮罩 (透過網址參數 $fields
或 fields
提供),或是使用 HTTP/gRPC 標頭 X-Goog-FieldMask
來執行這項操作。詳情請參閱「系統參數」。
欄位遮罩
欄位遮罩值是以逗號分隔的欄位路徑清單。每個欄位路徑都是以點號分隔的欄位名稱清單,用來代表郵件階層。欄位名稱是 JSON 物件鍵,或 protobuf 欄位標記名稱。欄位路徑從頂層回應訊息類型開始,可選擇後面加上一或多個點,然後是下一層的欄位名稱。一般來說,欄位路徑的建構方式如下:
topLevelField[.secondLevelField][.thirdLevelField][...]
特殊情況欄位遮罩是萬用字元「*」,可選取所有根層級欄位。
範例
以下範例說明如何為 ComputeRoutes()
方法設定欄位遮罩。
範例 1
所有可用欄位的欄位遮罩 (供人工檢查使用)。
X-Goog-FieldMask: *
範例 2
路線層級時間長度、距離和多邊形的欄位遮罩 (實際工作環境設定範例)。
X-Goog-FieldMask: routes.duration,routes.distanceMeters,routes.polyline
我們不建議在實際工作環境中使用萬用字元 (*) 回應欄位遮罩,或在頂層 (路徑) 指定欄位遮罩。只選取所需欄位:
如要進一步瞭解如何建構欄位路徑,請參閱 field_mask.proto。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2024-11-23 (世界標準時間)。
[[["容易理解","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"]],["上次更新時間:2024-11-23 (世界標準時間)。"],[[["\u003cp\u003eWhen calling the \u003ccode\u003eComputeRoutes()\u003c/code\u003e method, specify desired response fields using a field mask with the \u003ccode\u003e$fields\u003c/code\u003e URL parameter, \u003ccode\u003efields\u003c/code\u003e URL parameter, or \u003ccode\u003eX-Goog-FieldMask\u003c/code\u003e HTTP/gRPC header.\u003c/p\u003e\n"],["\u003cp\u003eConstruct field masks as comma-separated lists of dot-separated field paths representing the message hierarchy starting from the top-level response.\u003c/p\u003e\n"],["\u003cp\u003eFor production, avoid using wildcard field masks or selecting all top-level fields to improve performance, ensure stable latency, and reduce response size.\u003c/p\u003e\n"],["\u003cp\u003eSelecting specific fields instead of all fields minimizes server processing, safeguards against potential performance degradation from future response field additions, and enhances network throughput.\u003c/p\u003e\n"]]],["To specify which fields to return from the `ComputeRoutes()` method, use a response field mask via the `$fields`, `fields` URL parameter, or the `X-Goog-FieldMask` header. Field masks use comma-separated field paths, formatted as `topLevelField[.secondLevelField]`. Avoid the wildcard `*` or top-level `routes` in production. Instead, specify needed fields, like `routes.duration,routes.distanceMeters,routes.polyline`, to reduce latency, ensure stable performance, and decrease response size.\n"],null,["# Choose Fields to Return\n\nWhen you call the `ComputeRoutes()` method, you must specify which fields you\nwant returned in the response. You do it by using a response field mask, which\nyou provide with the URL parameter `$fields` or `fields`, or by using the\nHTTP/gRPC header `X-Goog-FieldMask`. For more information, see\n[System Parameters](https://cloud.google.com/apis/docs/system-parameters).\n\nField mask\n----------\n\nThe field mask value is a comma-separated list of field paths. Each field path\nis a dot-separated list of field names that represent the message hierarchy. A\nfield name is either the JSON object key, or the protobuf field tag name. The\nfield path starts from the top level response message type, and is optionally\nfollowed by one or more dots, and then the next level of field name. In general,\nfield paths are constructed in the following way: \n\n```\ntopLevelField[.secondLevelField][.thirdLevelField][...]\n```\n\nA special case field mask is a wildcard \"\\*\", which selects all root-level\nfields.\n\nExamples\n--------\n\nThe following example demonstrates how to set field masks for the\n`ComputeRoutes()` method.\n\n### Example 1\n\nField mask of all available fields (for manual inspection). \n\n```\nX-Goog-FieldMask: *\n```\n\n### Example 2\n\nField mask of Route-level duration, distance, and polyline (an example production setup). \n\n```\nX-Goog-FieldMask: routes.duration,routes.distanceMeters,routes.polyline\n```\n\nWe discourage the use of the wildcard (\\*) response field mask, or specifying\nthe field mask at the top level (routes) in production. Selecting just the\nfields that you need:\n\n- Allows our server to save processing cycles, which allows us to return your\n results with a lower latency.\n\n- Ensures stable latency performance. We might add more response fields in the\n future, and those new fields might require extra computation time. If you select\n all fields, or if you select all fields at top level, you might experience\n performance degradation because any new field that we add will be automatically\n included in your response.\n\n- Results in a smaller response size, which translates into higher network\n throughput.\n\nFor more information about how to construct field paths, see the\n[field_mask.proto](https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/field_mask.proto)."]]