When routes are calculated (including rerouting), the route that takes the least amount of time to navigate is returned as the default best route. But you can change the routing strategy so that the shorter of the route alternatives is returned instead.
The term shorter means that the route is the shortest among optimal routing results based on our default cost model. The shorter route might not be the absolute shortest route since that route might be a poor alternative. For example, when the absolute shortest route is 10 km and takes 50 minutes to navigate, while the optimal shorter route is 15 km and takes 20 minutes to navigate—wasting 30 mins to reduce five km isn't a good trade-off.
Once you set the routing strategy for a trip, it won't change until the trip completes. To change the routing strategy, you must clear the destinations and reset them again with the new routing strategy.
Setting the routing strategy
You can configure navigation to use the shorter route routing strategy by
setting RoutingOptions.routingStrategy
when you call setDestinations()
.
RoutingOptions.routingStrategy
takes one of the following two enumeration
values:
Enumeration Value | Description |
---|---|
RoutingStrategy.DEFAULT_BEST | Ranks routes by the Navigation SDK's default cost model. This is the default routing strategy. |
RoutingStrategy.SHORTER | Ranks routes by distance. The highest ranking route is the shortest of those returned. |
Example
The following code example demonstrates how to set the shorter route routing strategy.
RoutingOptions routingOptions = new RoutingOptions();
routingOptions.routingStrategy(RoutingStrategy.SHORTER);
navigator.setDestinations(destinations, routingOptions, displayOptions);
Route details
When the shorter route takes too long, the default best route is the better
choice. You can compare routing strategies by calling getRouteInfo()
to get
route details for each. Details include the duration, and the distance to a
destination waypoint.
Getting route details
You can retrieve route details for both routing strategies (the default best
route and the shorter route) for a single waypoint. These details come from
RouteInfo
, and are returned in a ListenableResultFuture
.
Example
The following code example demonstrates how to get route details for each of the two routing strategies.
ListenableResultFuture<RouteInfo> routeInfoFuture =
navigator.getRouteInfo(waypoint, routingOptions);
The route callout format
Under the shorter route routing strategy, callouts along the route display distance details. But you can use the ETA callouts instead.
Configuring the route callout format
You can change the route callout format by calling setRouteCalloutInfoFormat
in NavigationView
(or in NavigationFragment
). setRouteCalloutInfoFormat
takes one of the following enumeration values:
Enumeration Value | Description |
---|---|
RouteCalloutInfoFormat.DEFAULT | Displays time remaining when using the default best route routing strategy. Displays distance remaining when using the shorter route routing strategy. |
RouteCalloutInfoFormat.TIME | Displays time remaining. |
RouteCalloutInfoFormat.DISTANCE | Displays distance remaining. |
Example
The following code example demonstrates how to configure the route callout format.
mNavFragment.setRouteCalloutInfoFormat(RouteCalloutInfoFormat.TIME);