onRouteAlternatives

abstract fun onRouteAlternatives(    routeProgress: RouteProgress,     alternatives: List<DirectionsRoute>,     routerOrigin: RouterOrigin)

Invoked whenever available alternative routes to the destination change.

This callback if invoked whenever new alternatives are available (addition to the list), or when a fork between an alternative and the current primary route has been passed (removal from the list).

The alternatives list always represent all available, up-to-date, alternatives for the current route.

The alternatives are not automatically added to MapboxNavigation, you need to add them manually to trigger RoutesObserver, for example:

mapboxNavigation.registerRouteAlternativesObserver(
RouteAlternativesObserver { routeProgress, alternatives, routerOrigin ->
val newRoutes = mutableListOf<DirectionsRoute>().apply {
add(mapboxNavigation.getRoutes().first())
addAll(alternatives)
}
mapboxNavigation.setRoutes(newRoutes)
}
)

You can filter the alternatives out before setting them back to MapboxNavigation based on requirements.

Parameters

routeProgress

the current route's progress.

alternatives

list of alternative routes, can be empty.

routerOrigin

reports the source of all the new alternative routes in the list. If there are no new routes, reports the source that returned the latest additions.