Rerouting
Rerouting is when a new route is generated after the user's progress along a route has already begun. There are a few reasons rerouting happens including the user going off-route and the Navigation SDK determining there is a faster route to the next waypoint from the user's current location.
Off-route detection
The Navigation SDK provides information about whether a user's device is on the route that was generated. If a user is off-route, you can provide additional instruction to the user and generate a new route.
The RouteController
's userIsOnRoute
property uses the device location to check if a user is on or off the current route and returns a boolean.
By default, if a user is off-route, a new route is generated from their current location to the next waypoint. NavigationServiceDelegate.navigationService(_:willRerouteFrom:)
is called and Notification.Name.routeControllerWillReroute
is posted after the SDK detects the need for a reroute but before receiving the new route. Then NavigationServiceDelegate.navigationService(_:didRerouteAlong:at:proactive:)
is called and Notification.Name.routeControllerDidReroute
is posted once you receive the new route. You can use these methods to customize built-in behavior and synchronize your application behavior with what's happening with navigation logic.
You can also preempt rerouting on a case-by-case basis using the NavigationServiceDelegate.navigationService(_:shouldRerouteFrom:)
delegate method.
Faster-route detection
By default, the Navigation SDK checks for a faster route every two minutes by making a request to the Direction API and comparing the response to the current route.
You can customize the interval at which to check for a faster route by setting the RouteControllerProactiveReroutingInterval
global variable. You can opt-out of faster-route detection by setting navigationService.router.reroutesProactively
to false
.
navigationService.router.reroutesProactively = false