Chỉ định các đối tượng địa lý tuyến đường để tránh
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.
Nhà phát triển ở Khu vực kinh tế Châu Âu (EEA)
Bạn chỉ định những tính năng tuyến đường mà bạn muốn tránh, chẳng hạn như tránh trạm thu phí hoặc đường cao tốc, bằng cách thêm tính năng sửa đổi tuyến đường vào yêu cầu. Sau đó, API sẽ cố gắng cung cấp một tuyến không yêu cầu các tính năng đó.
RouteModifiers. Bạn có thể chỉ định avoidTolls, avoidHighways, avoidFerries và avoidIndoor.
Việc chỉ định đối tượng sửa đổi tuyến đường không nhất thiết phải loại bỏ các tuyến đường có chứa tính năng bị hạn chế. API sử dụng đối tượng sửa đổi để thiên vị kết quả cho các tuyến đường thuận lợi hơn. Có thể có một số lý do khiến việc yêu cầu một lựa chọn tránh không thay đổi tuyến đường của bạn. Ví dụ: tuyến đường duy nhất từ điểm xuất phát đến điểm đến khiến bạn không thể tránh xa đường cao tốc hoặc phà. Hoặc tuyến đường thay thế thực sự làm tăng đáng kể thời gian di chuyển.
Ví dụ sau đây minh hoạ cách đặt đối tượng sửa đổi tuyến trong phần nội dung yêu cầu của phương thức computeRoutes (REST). Bạn cũng có thể chỉ định tuỳ chọn này cho phương thức ComputeRoutes (gRPC). Trong ví dụ này, bạn chỉ định tránh trạm thu phí và đường cao tốc:
[null,null,["Cập nhật lần gần đây nhất: 2025-06-20 UTC."],[[["\u003cp\u003eThe Routes API's Compute Route Matrix feature does not support avoiding route features.\u003c/p\u003e\n"],["\u003cp\u003eYou can request routes that avoid tolls, highways, ferries, and indoor travel using the \u003ccode\u003erouteModifiers\u003c/code\u003e property.\u003c/p\u003e\n"],["\u003cp\u003eWhile route modifiers bias the results, they may not eliminate the specified features if alternatives are unavailable or significantly increase travel time.\u003c/p\u003e\n"],["\u003cp\u003eYou can specify route modifiers in both REST and gRPC requests, using the \u003ccode\u003eavoidTolls\u003c/code\u003e, \u003ccode\u003eavoidHighways\u003c/code\u003e, \u003ccode\u003eavoidFerries\u003c/code\u003e, and \u003ccode\u003eavoidIndoor\u003c/code\u003e fields within the \u003ccode\u003erouteModifiers\u003c/code\u003e property.\u003c/p\u003e\n"]]],["Route modifiers, set in the `routeModifiers` property of a request, allow users to express preferences for avoiding tolls, highways, ferries, or indoor routes. The `Compute Route Matrix` feature does not support avoiding route features. Modifiers bias the route calculation, but do not guarantee avoidance. `routeModifiers` also supports `vehicleInfo` and `tollPasses`. The API might include the feature to be avoided if no practical alternative exists. An example in a `computeRoutes` request demonstrates setting `avoidTolls` and `avoidHighways` to `true`.\n"],null,["# Specify route features to avoid\n\n**European Economic Area (EEA) developers** If your billing address is in the European Economic Area, effective on 8 July 2025, the [Google Maps Platform EEA Terms of Service](https://cloud.google.com/terms/maps-platform/eea) will apply to your use of the Services. Functionality varies by region. [Learn more](/maps/comms/eea/faq).\n| **Note:** Avoiding route features is not supported by the Compute Route Matrix feature of the Routes API.\n\nYou specify which route features you prefer to avoid, such as avoiding tolls or\nhighways, by adding *route modifiers* to a request. The API then attempts to\nprovide a route that does not require those features.\n\nUse the `routeModifiers` property in a request, of type\n[RouteModifiers](/maps/documentation/routes/reference/rest/v2/RouteModifiers). You can specify `avoidTolls`,\n`avoidHighways`, `avoidFerries`, and `avoidIndoor`.\n| **Note:** The `routeModifiers` property supports additional options, including `vehicleInfo` and `tollPasses`. For more on `vehicleInfo`, see [Get an eco-friendly route](/maps/documentation/routes/eco-routes). For more on `tollPasses`, see [Calculate toll fees for a route](/maps/documentation/routes/calculate_toll_fees).\n\nSpecifying a route modifier does not necessarily eliminate routes that include\nthe restricted feature. The API uses the modifier to bias the result to more\nfavorable routes. There can be a few reasons why requesting an avoidance option\ndoesn't change your route. For example, the only route from the origin to the\ndestination makes it impossible to avoid a highway or ferry. Or, the alternate\nroute actually lengthens travel time significantly.\n\nThe following example demonstrates how to set route modifiers in a\n[computeRoutes](/maps/documentation/routes/reference/rest/v2/TopLevel/computeRoutes)\nmethod (REST) request body. You can also specify this option to the\n[ComputeRoutes](/maps/documentation/routes/reference/rpc/google.maps.routing.v2#google.maps.routing.v2.Routes.ComputeRoutes)\nmethod (gRPC). In this example, you specify to avoid tolls and highways: \n\n```json\n{\n \"origin\":{\n \"location\":{\n \"latLng\":{\n \"latitude\":37.419734,\n \"longitude\":-122.0827784\n }\n }\n },\n \"destination\":{\n \"location\":{\n \"latLng\":{\n \"latitude\":37.417670,\n \"longitude\":-122.079595\n }\n }\n },\n \"routeModifiers\": {\n \"avoidTolls\": true,\n \"avoidHighways\": true,\n }\n}\n```"]]