Оптимизируйте свои подборки
Сохраняйте и классифицируйте контент в соответствии со своими настройками.
Разработчики Европейской экономической зоны (ЕЭЗ)
По умолчанию API маршрутов возвращает маршрут по умолчанию , который обычно является самым быстрым из пункта отправления в пункт назначения. При запросе альтернативных маршрутов API возвращает до трёх маршрутов наряду с маршрутом по умолчанию. Ваши клиенты могут выбрать маршрут, который наилучшим образом соответствует их требованиям.
Соображения при запросе альтернативных маршрутов
При запросе альтернативных маршрутов примите во внимание следующие моменты:
Запрос альтернативных маршрутов возможен только для маршрутов без промежуточных точек. Запрос альтернативных маршрутов, если в маршруте указаны промежуточные точки, не приводит к ошибке. Однако альтернативные маршруты не возвращаются.
Ответ содержит максимум три альтернативных маршрута. Однако иногда альтернативные маршруты недоступны, поэтому ответ содержит только маршрут по умолчанию.
Из-за дополнительной обработки, необходимой для расчета альтернативных маршрутов, запрос альтернативных маршрутов может увеличить время отклика API.
Пример запроса альтернативных маршрутов
Установите computeAlternativeRoutes в true , чтобы запросить альтернативные маршруты. В следующем примере показано, как запросить альтернативные маршруты в запросе метода computeRoutes (REST).
В этом примере вы указываете маску поля, чтобы ответ содержал только свойства duration , distanceMeters, и routeLabels для каждого маршрута. Клиент затем может использовать эту информацию для выбора маршрута. Подробнее см. в разделе Выбор возвращаемой информации .
Пример ответа на альтернативные маршруты
В ответе используйте свойство массива routeLabels для определения достижимого маршрута:
Для маршрута по умолчанию свойство routeLabels содержит DEFAULT_ROUTE .
Для любых альтернативных маршрутов свойство routeLabels содержит DEFAULT_ROUTE_ALTERNATE .
В этом примере ответ содержит маршрут по умолчанию и два альтернативных маршрута. Обратите внимание, что значения свойств duration и distanceMeters различаются для каждого маршрута:
[[["Прост для понимания","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-09-04 UTC."],[[["\u003cp\u003eThe Routes API can return up to three alternative routes in addition to the default route, allowing users to choose the best option for their needs.\u003c/p\u003e\n"],["\u003cp\u003eAlternative routes can only be requested for routes without intermediate waypoints and may increase API response time.\u003c/p\u003e\n"],["\u003cp\u003eThe response identifies routes using \u003ccode\u003erouteLabels\u003c/code\u003e: \u003ccode\u003eDEFAULT_ROUTE\u003c/code\u003e for the default route and \u003ccode\u003eDEFAULT_ROUTE_ALTERNATE\u003c/code\u003e for alternative routes.\u003c/p\u003e\n"],["\u003cp\u003eYou can include polylines in the response to display routes on a map by adding \u003ccode\u003eroutes.polyline\u003c/code\u003e to the field mask.\u003c/p\u003e\n"]]],["The Routes API can compute alternative routes by setting `computeAlternativeRoutes` to `true`. It returns up to three alternative routes, besides the default fastest route, for requests without intermediate waypoints. Alternative routes may increase response time and aren't always available. Each route's `routeLabels` array indicates if it's the default (`DEFAULT_ROUTE`) or an alternative (`DEFAULT_ROUTE_ALTERNATE`). You can include route polylines by adding `routes.polyline` in the field mask, enabling visual display on a map.\n"],null,["# Get alternative routes\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:** Alternative routes are not supported by the Compute Route Matrix feature of the Routes API.\n\nBy default, the Routes API returns the *default* route, which is typically\nthe fastest route from the origin to the destination. When you request\n*alternative* routes, the API returns up to three routes along with the default\nroute. Your customers can then choose a route that best fits their requirements.\n\nConsiderations when requesting alternative routes\n-------------------------------------------------\n\nTo request alternative routes, be aware of the following considerations:\n\n- You can only request alternative routes for routes without intermediate\n waypoints. Requesting alternative routes when the route specifies\n intermediate waypoints does not cause an error. However, no alternative\n routes are returned.\n\n- The response contains a maximum of three alternative routes. However,\n sometimes no alternative routes are available so the response only contains\n the default route.\n\n- Because of the additional processing required to calculate alternative\n routes, requesting alternative routes might increase the response time of\n the API.\n\nExample alternative routes request\n----------------------------------\n\nSet `computeAlternativeRoutes` to `true` to request alternative routes. The\nfollowing example shows how to request alternative routes in a\n[computeRoutes](/maps/documentation/routes/reference/rest/v2/TopLevel/computeRoutes)\nmethod (REST) request. \n\n```json\ncurl -X POST -d '{\n \"origin\":{\n \"location\":{\n \"latLng\":{\n \"latitude\":42.340173523716736,\n \"longitude\":-71.05997968330408\n }\n }\n },\n \"destination\":{\n \"location\":{\n \"latLng\":{\n \"latitude\":42.075698891472804,\n \"longitude\": -72.59806562080408\n }\n }\n },\n \"travelMode\": \"DRIVE\",\n \"routingPreference\":\"TRAFFIC_AWARE\",\n \"computeAlternativeRoutes\": true\n}' \\\n-H 'Content-Type: application/json' -H 'X-Goog-Api-Key: YOUR_API_KEY' \\\n-H 'X-Goog-FieldMask: routes.duration,routes.distanceMeters,routes.routeLabels' \\\n'https://routes.googleapis.com/directions/v2:computeRoutes'\n```\n\nIn this example, you specify a field mask so that the response contains only the\n`duration`, `distanceMeters,` and `routeLabels` properties for each route. Your\ncustomer can then use that information to choose which route to take. For more\ninformation, see [Choose what information to return](/maps/documentation/routes/choose_fields).\n\nExample alternative routes response\n-----------------------------------\n\nIn the response, use the `routeLabels` array property to identify reach\nroute:\n\n- For the default route, the `routeLabels` property contains\n `DEFAULT_ROUTE`.\n\n- For any alternate routes, the `routeLabels` property contains\n `DEFAULT_ROUTE_ALTERNATE`.\n\n| **Note:** You can also request an eco-friendly route by setting the `requestedReferenceRoutes` property to `FUEL_EFFICIENT` in the request. For the eco-friendly route, the `routeLabels` property contains `FUEL_EFFICIENT`. For more on eco-friendly routing, see [Get eco-friendly routes](/maps/documentation/routes/eco-routes).\n\nIn this example, the response contains the default route and two alternative\nroutes. Notice that the values of the `duration` and `distanceMeters` properties\nare different for each route: \n\n```json\n{\n \"routes\": [\n {\n \"distanceMeters\": 150322,\n \"duration\": \"5309s\",\n \"routeLabels\": [\n \"DEFAULT_ROUTE\"\n ]\n },\n {\n \"distanceMeters\": 157614,\n \"duration\": \"6879s\",\n \"routeLabels\": [\n \"DEFAULT_ROUTE_ALTERNATE\"\n ]\n },\n {\n \"distanceMeters\": 189311,\n \"duration\": \"7376s\",\n \"routeLabels\": [\n \"DEFAULT_ROUTE_ALTERNATE\"\n ]\n }\n ]\n}\n```\n\n### Include polylines in the response\n\nTo make it easier for the user to select the route, add the\n[polyline](/maps/documentation/routes/traffic_on_polylines) for each route to the response. You can then\ndisplay each polyline on a map.\n\nTo add the polyline, include `routes.polyline` in the field mask: \n\n```json\n-H 'X-Goog-FieldMask: routes.duration,routes.distanceMeters,routes.routeLabels,routes.polyline'\n```\n\nThe response then contains the polyline for each route: \n\n```json\n{\n \"routes\": [\n {\n \"distanceMeters\": 150322,\n \"duration\": \"5309s\",\n \"polyline\": {\n \"encodedPolyline\": \"mrlaGtavpLPLBTm...PgA^qC\"\n },\n \"routeLabels\": [\n \"DEFAULT_ROUTE\"\n ]\n },\n {\n \"distanceMeters\": 157614,\n \"duration\": \"6879s\",\n \"polyline\": {\n \"encodedPolyline\": \"DmEd`@e@pCo@pCs@z...PgA^qC\"\n },\n \"routeLabels\": [\n \"DEFAULT_ROUTE_ALTERNATE\"\n ]\n },\n {\n \"distanceMeters\": 189311,\n \"duration\": \"7376s\",\n \"polyline\": {\n \"encodedPolyline\": \"FVLL|Af@HPAV...PgA^qC\"\n },\n \"routeLabels\": [\n \"DEFAULT_ROUTE_ALTERNATE\"\n ]\n }\n ]\n}\n```"]]