Navigation SDK for Android
Beta

Off-route detection

The Navigation SDK detects when a device strayed from a route it was navigating. When a device is determined to be off route, the SDK provides notifications and takes actions to keep the user navigating.

The OffRouteObserver interface provides a boolean whenever the Navigation SDK is in turn-by-turn navigation and is off route. When the device is determined to be off route, the Navigation SDK will automatically request a new route.

Create the OffRouteObserver interface object:

val offRouteObserver = object : OffRouteObserver {
    override fun onOffRouteStateChanged(offRoute: Boolean) {

    }
}
Note

This interface doesn't work with free-drive mode.

Register the OffRouteObserver object with your already-instantiated MapboxNavigation object.

override fun onStart() {
        super.onStart() 
        mapView.onStart()
                 mapboxNavigation.registerOffRouteObserver(offRouteObserver)
}

Don’t forget to unregister the OffRouteObserver interface:

override fun onStop() {
    super.onStop()  
    mapView.onStop()

    mapboxNavigation.unregisterOffRouteObserver(offRouteObserver)
}
Was this page helpful?