Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Khi xác định tuyến đường tốt nhất cho một chuyến đi chung xe, tuyến đường nhanh nhất chưa chắc đã phải là lựa chọn tốt nhất. Bạn có thể muốn lên kế hoạch cho tuyến đường của mình.
Routes Preferred API cho phép bạn lập kế hoạch cho một tuyến đường bằng cách chỉ định mục tiêu của tuyến đường bằng phương thức ComputeCustomRoutes.
Phương thức ComputeCustomRoutes cũng có thể giúp bạn tuân thủ lộ trình bằng cách giảm thiểu sự khác biệt giữa lộ trình do người vận hành chọn và lộ trình đã lái.
Sử dụng cả Routes Preferred API và Navigation SDK để khai thác tối đa lợi ích của việc lập kế hoạch tuyến đường.
Bật phương thức ComputeCustomRoutes
Trước khi có thể sử dụng phương thức ComputeCustomRoutes trong mã, bạn phải bật phương thức này. Để biết thêm thông tin về cách bật các phương thức Routes Preferred API, hãy xem phần Bắt đầu sử dụng.
Sử dụng phương thức ComputeCustomRoutes
Phương thức ComputeCustomRoutes yêu cầu bạn chỉ định một mặt nạ trường phản hồi trong dữ liệu đầu vào. Bạn có thể cung cấp mặt nạ trường phản hồi bằng cách sử dụng tham số URL $fields hoặc fields, hoặc bằng cách sử dụng tiêu đề HTTP/gRPC X-Goog-FieldMask. Để biết thêm thông tin, hãy xem phần Tham số hệ thống.
Giá trị mặt nạ trường là một danh sách đường dẫn trường được phân tách bằng dấu phẩy. Mỗi đường dẫn trường là một danh sách tên trường được phân tách bằng dấu chấm, đại diện cho hệ thống phân cấp thông báo.
Tên trường là khoá đối tượng JSON hoặc tên thẻ trường protobuf.
Đường dẫn trường bắt đầu từ loại thông báo phản hồi cấp cao nhất, sau đó có thể có một hoặc nhiều dấu chấm, rồi đến tên trường cấp tiếp theo. Nhìn chung, đường dẫn trường được tạo theo cách sau:
[[["Dễ hiểu","easyToUnderstand","thumb-up"],["Giúp tôi giải quyết được vấn đề","solvedMyProblem","thumb-up"],["Khác","otherUp","thumb-up"]],[["Thiếu thông tin tôi cần","missingTheInformationINeed","thumb-down"],["Quá phức tạp/quá nhiều bước","tooComplicatedTooManySteps","thumb-down"],["Đã lỗi thời","outOfDate","thumb-down"],["Vấn đề về bản dịch","translationIssue","thumb-down"],["Vấn đề về mẫu/mã","samplesCodeIssue","thumb-down"],["Khác","otherDown","thumb-down"]],["Cập nhật lần gần đây nhất: 2025-07-22 UTC."],[[["\u003cp\u003eThe Routes Preferred API's \u003ccode\u003eComputeCustomRoutes\u003c/code\u003e method enables planning routes based on objectives beyond the fastest route, such as compliance or driver preferences.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eComputeCustomRoutes\u003c/code\u003e supports optimizing routes for \u003ccode\u003eDRIVE\u003c/code\u003e and \u003ccode\u003eTWO_WHEELER\u003c/code\u003e travel modes, but excludes intermediate waypoints and other travel modes.\u003c/p\u003e\n"],["\u003cp\u003eUsing the Routes Preferred API with the Navigation SDK provides the best route planning outcomes, though they can utilize separate cloud projects.\u003c/p\u003e\n"],["\u003cp\u003eBefore using the \u003ccode\u003eComputeCustomRoutes\u003c/code\u003e method, enable it and verify your quota limits, requesting increases if necessary through Google Cloud Support.\u003c/p\u003e\n"],["\u003cp\u003eTo specify desired data in the response, use field masks with the \u003ccode\u003eComputeCustomRoutes\u003c/code\u003e method, selecting fields using dot-separated paths from the top-level response.\u003c/p\u003e\n"]]],["The Routes Preferred API's `ComputeCustomRoutes` method allows route planning by specifying a route objective and minimizing deviations from the operator's selected route. This method supports `DRIVE` and `TWO_WHEELER` travel modes, excluding `via` waypoints. To use it, enable the method and specify a response field mask via `$fields`, `fields`, or `X-Goog-FieldMask`. Quota limits should be monitored. Use alongside the Navigation SDK to maximize route planning benefits. Additionally, toll fees can be calculated using this API.\n"],null,["# Plan a Route\n\n\u003cbr /\u003e\n\n| This product or feature is in Preview (pre-GA). Pre-GA products and features might have limited support, and changes to pre-GA products and features might not be compatible with other pre-GA versions. Pre-GA Offerings are covered by the [Google\n| Maps Platform Service Specific Terms](https://cloud.google.com/maps-platform/terms/maps-service-terms). For more information, see the [launch stage\n| descriptions](/maps/launch-stages).\n\n\u003cbr /\u003e\n\nWhen you are determining the best route for a ridesharing trip, the\nfastest route may not always be the best option. You may want\nto plan your route.\n\nThe Routes Preferred API lets you plan a route by specifying\na route objective using the `ComputeCustomRoutes` method.\n\nThe `ComputeCustomRoutes` method can also help with route compliance by letting\nyou minimize the difference between the route selected by the operator and the\nroute driven.\n\nUse both the Routes Preferred API and the\n[Navigation SDK](https://developers.google.com/maps/documentation/navigation-sdk)\nto realize the full benefit of route planning.\n| **Note:** You do not have to use the same cloud project for the Routes Preferred API and the Navigation SDK.\n| **Note:** Unlike `ComputeRoutes` API, `ComputeCustomRoutes` only supports two travel modes, `DRIVE` (or the equivalent `TRAVEL_MODE_UNSPECIFIED`) and `TWO_WHEELER`. This method also does not support `via` intermediate waypoints. If you try to use other travel modes or `via` waypoints, the request fails. For more information about `via` waypoints, see [Routes Preferred API waypoints](/maps/documentation/routes_preferred/reference/rest/Shared.Types/Waypoint).\n\nEnable the ComputeCustomRoutes method\n-------------------------------------\n\nBefore you can use the `ComputeCustomRoutes` method in your code, you must\nenable it. For more information on enabling Routes Preferred API\nmethods, see [Getting Started](/maps/documentation/routes_preferred/get_started).\n| **Important:** Check your quota limits for Routes Preferred API methods. If you need to increase your quota limits, contact support by filing a case on the [Google Maps Platform support page](https://console.cloud.google.com/google/maps-apis/support) in the Google Cloud Console, or by calling the [Google Cloud Support Hotline](/maps/documentation/routes_preferred/support#support_hotline).\n\nUse the ComputeCustomRoutes method\n----------------------------------\n\nThe `ComputeCustomRoutes` method requires that you specify a response\nfield mask in the input. You can provide the response field mask by using\nthe URL parameter `$fields` or `fields`, or by using the HTTP/gRPC header\n`X-Goog-FieldMask`. For more information, see\n[System Parameters](https://cloud.google.com/apis/docs/system-parameters).\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.\nA field name is either the JSON object key, or the protobuf field tag name.\nThe field path starts from the top level response message type,\nand is optionally followed by one or more dots, and then the next level\nof field name. In general, field 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\nFor more information, see:\n\n- [**gRPC API reference**](/maps/documentation/routes_preferred/reference/rpc/google.maps.routes.v1)\n- [**REST API reference**](/maps/documentation/routes_preferred/reference/rest/v1/TopLevel/computeCustomRoutes)\n\nFor examples of using the `ComputeCustomRoutes` method, see\n[Computing a Custom Route (Beta) Examples](/maps/documentation/routes_preferred/custom_route_examples).\n\nCalculating toll fees\n---------------------\n\nFor information on calculating toll fees, see\n[Calculate toll fees](/maps/documentation/routes_preferred/calculate_toll_fees).\n\nFor examples of calculating toll fees, see\n[Computing a Custom Route Examples](/maps/documentation/routes_preferred/custom_route_examples#toll-fee-examples)."]]