Search code examples
mapboxmapbox-android

How to prevent auto re-route on off route in Mapbox


I was trying to prevent the MapboxNavigation from automatically finding a new route, when the user is detected as off-route, since I would like to perform another action instead.

I used the OffRouteObserver to perform this action and it is running, but it seems that the Re-route is still executed.

In the MapboxNavigation.kt file, there is an internal off route observer which calls reroute() function when off route is detected. I have no idea how to change this.

If this feature is possible, please let me know. Thank you


Solution

  • I see a few options that you can do:

    1. Override the default reroute controller, see MapboxNavigation.setRerouteController;
    2. You can wait for new routes on re-route (see MapboxNavigation.registerRoutesObserver) and check if they were fetched from OnBoard tiles, then do what you want to do with it. To check where routes were fetched from, you need to invoke NavigationRoute.origin;
    3. If both above options are not working, please open a feature request in mapbox-android-navigation repo;