[null,null,["最后更新时间 (UTC):2025-08-31。"],[[["\u003cp\u003eThe Navigation SDK offers two routing strategies: the default best route (prioritizes time) and the shorter route (prioritizes distance among optimal routes).\u003c/p\u003e\n"],["\u003cp\u003eYou can retrieve route details using \u003ccode\u003egetRouteInfoForDestination()\u003c/code\u003e to compare the default best route and the shorter route.\u003c/p\u003e\n"],["\u003cp\u003eCustomize routing strategy with \u003ccode\u003eGMSNavigationRoutingOptions\u003c/code\u003e, including ferry inclusion with \u003ccode\u003eavoidsFerries\u003c/code\u003e and route callout format with \u003ccode\u003erouteCalloutFormat\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eTo change an active trip's routing strategy, you must clear existing destinations and re-set them with the desired strategy.\u003c/p\u003e\n"],["\u003cp\u003eThe shorter route strategy is designed for Rideshare providers operating in regulated markets where pricing is primarily based on distance traveled.\u003c/p\u003e\n"]]],[],null,["# Adjust routing preferences\n\nRoute calculations (including rerouting) return the route that takes the\nleast amount of time to navigate as the *default best route*. But\nyou can change the routing strategy so that the shorter of the route\nalternatives is returned instead.\n\nThe term *shorter* means the route that is the shortest among optimal route\nbased on our default cost model. The shorter route might not be the *absolute*\nshortest route, since that option might be a poor alternative. For example, if\nthe absolute shortest route is 10 km and takes 50 minutes to navigate and\nanother route is 15 km, but only takes 20 minutes to navigate, the second choice\nis optimal, because spending 30 mins to reduce five km isn't a good trade-off.\n\nOnce you set the routing strategy for a trip, it won't change until the trip\ncompletes. To change the routing strategy for an existing trip, you must clear\nthe destinations and reset them again with the new routing strategy.\n| **Note:** The feature mentioned above is intended for Rideshare providers that operate in regulated markets (such as Europe), who are often required by law to price their services based on the same principles as traditional taxis---which charge based primarily on the distance traveled.\n\nGetting route details\n---------------------\n\nTo determine which route strategy is the optimal choice for a given waypoint,\ncall `getRouteInfoForDestination()` to get route details for both the default\nbest route and the absolute shorter route. Details include the duration and the\ndistance to a destination waypoint.\n\nThese details come from\n[`GMSNavigationRouteInfo`](/maps/documentation/navigation/ios-sdk/reference/objc/Classes/GMSNavigationRouteInfo)\nin the callback.\n\n### Example\n\nThe following code example demonstrates how to get route details for each of the\ntwo routing strategies.\n\n\u003cbr /\u003e\n\n### Swift\n\n\u003cbr /\u003e\n\n let routingOptions = GMSNavigationRoutingOptions()\n navigator?.getRouteInfoForDestination(destination,\n routingOptions: routingOptions) { routeInfo in\n ...\n }\n\n\u003cbr /\u003e\n\n### Objective-C\n\n\u003cbr /\u003e\n\n GMSNavigationRoutingOptions *routingOptions =\n [[GMSNavigationRoutingOptions alloc] init];\n [navigator getRouteInfoForDestination:destination\n withRoutingOptions:routingOptions\n callback:^(GMSNavigationRouteInfo *routeInfo){...}];\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\nSetting the routing strategy\n----------------------------\n\nYou can configure the routing strategy by using `GMSNavigationRoutingOptions`,\nand setting the `routingStrategy` when calling `setDestinations()`.\n\n`routingStrategy` takes one of the following enumeration values:\n\n| Enumeration Value | Description |\n|-----------------------------------------|----------------------------------------------------------------------------------------------|\n| GMSNavigationRoutingStrategyDefaultBest | Ranks routes by the Navigation SDK default cost model. This is the default routing strategy. |\n| GMSNavigationRoutingStrategyShorter | Ranks routes by distance. The highest ranking route is the shortest of those returned. |\n\n| **Warning:** This feature is incompatible with the [Hiding Alternate Route](/maps/documentation/navigation/ios-sdk/controls#hiding_alternate_routes) feature. Using these two features at the same time will produce unexpected results.\n\n### Example\n\nThe following code example demonstrates how to set the shorter route routing\nstrategy.\n\n\u003cbr /\u003e\n\n### Swift\n\n\u003cbr /\u003e\n\n let routingOptions = GMSNavigationRoutingOptions(routingStrategy: .shorter)\n navigator?.setDestinations(destinations,\n routingOptions: routingOptions) { routeStatus in\n ...\n }\n\n\u003cbr /\u003e\n\n### Objective-C\n\n\u003cbr /\u003e\n\n GMSNavigationRoutingOptions *routingOptions = [[GMSNavigationRoutingOptions alloc] initWithRoutingStrategy:GMSNavigationRoutingStrategyShorter];\n [navigator setDestinations:destinations\n routingOptions:routingOptions\n callback:^(GMSRouteStatus routeStatus){...}];\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\nRoutes that include ferries\n---------------------------\n\nBy default, the Navigation SDK for iOS excludes routes that include ferries. If you prefer to\ninclude ferry options as part of your routes, you can adjust this routing\npreference to expose the trip to ferry segments by setting `avoidsFerries` to\n`false`.\n\n### Example\n\n\u003cbr /\u003e\n\n### Swift\n\n\u003cbr /\u003e\n\n self.mapView.navigator?.avoidsFerries = false\n\n\u003cbr /\u003e\n\n### Objective-C\n\n\u003cbr /\u003e\n\n self.mapView.navigator.avoidsFerries = NO\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\nThe route callout format\n------------------------\n\nUnder the shorter route routing strategy, callouts along the route display\ndistance details. But you can use the ETA callouts instead.\n\n### Configuring the route callout format\n\nYou can change the route callout format by setting `routeCalloutFormat` in\n`GMSMapView`. `routeCalloutFormat` takes one of the following enumeration\nvalues:\n\n| Enumeration Value | Description |\n|-----------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------|\n| GMSNavigationRouteCalloutFormatDefault | Displays time remaining when using the default best route routing strategy. Displays distance remaining when using the shorter route routing strategy |\n| GMSNavigationRouteCalloutFormatTime | Displays time remaining. |\n| GMSNavigationRouteCalloutFormatDistance | DDisplays distance remaining. |\n\n#### Example\n\nThe following code example demonstrates how to configure the route callout\nformat.\n\n\u003cbr /\u003e\n\n### Swift\n\n\u003cbr /\u003e\n\n self.mapView.routeCalloutFormat = .time\n\n\u003cbr /\u003e\n\n### Objective-C\n\n\u003cbr /\u003e\n\n _mapView.routeCalloutFormat = GMSNavigationRouteCalloutFormatTime;\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e"]]