OnlineRouteAlternativesSwitch

class OnlineRouteAlternativesSwitch(    connectTimeoutMilliseconds: Int,     readTimeoutMilliseconds: Int,     minimumRetryInterval: Int,     avoidManeuverSeconds: Int = DEFAULT_AVOID_MANEUVER_SECONDS_FOR_ROUTE_ALTERNATIVES) : MapboxNavigationObserver

This components replaces offline route by an online alternative when it's available. Under the hood it's requesting routes in cycle from the current position until the first successful result. Normally this job should be done by the SDK. The problem is that it currently relies on platform reachability/connectivity notifications. However some environments don't have working reachability/connectivity API. This class is a temporary workaround for those environments until we reimplement route alternatives logic so that it handles offline-online switch even if platform's reachability API doesn't work.

To enable automatic online-offline switch functionality, attach an instance of this class to MapboxNavigation using MapboxNavigationApp.registerObserver. If you want to disable automatic switch at runtime, detach it by invoking MapboxNavigationApp.unregisterObserver.

Example:

MapboxNavigationApp.registerObserver(OnlineRouteAlternativesSwitch())

If you don't use MapboxNavigationApp, you can enable the switch logic by calling OnlineRouteAlternativesSwitch.onAttached when MapboxNavigation instance is created, and then OnlineRouteAlternativesSwitch.onDetached when it is destroyed.

Known limitations: this class doesn't use user provided router. Warning: this is a temporary solution and will be removed in the next versions of the SDK.

Parameters

connectTimeoutMilliseconds
  • is forwarded to OkHttp as is

readTimeoutMilliseconds
  • is forwarded to OkHttp as is

minimumRetryInterval
  • defines an interval that limits how often routes will be requested. Route requests won't happen more often than this interval.

Constructors

Link copied to clipboard
fun OnlineRouteAlternativesSwitch(    connectTimeoutMilliseconds: Int,     readTimeoutMilliseconds: Int,     minimumRetryInterval: Int,     avoidManeuverSeconds: Int = DEFAULT_AVOID_MANEUVER_SECONDS_FOR_ROUTE_ALTERNATIVES)

Functions

Link copied to clipboard
open override fun onAttached(mapboxNavigation: MapboxNavigation)

Signals that the mapboxNavigation instance is ready for use. Use this function to register mapboxNavigation observers, such as MapboxNavigation.registerRoutesObserver.

Link copied to clipboard
open override fun onDetached(mapboxNavigation: MapboxNavigation)

Signals that the mapboxNavigation instance is being detached. Use this function to unregister mapboxNavigation observers that were registered in onAttached.