RouterDelegate
A router delegate interacts with one or more Router
instances, such as RouteController
objects, during turn-by-turn navigation. This protocol is similar to NavigationServiceDelegate
, which is the main way that your application can synchronize its state with the SDK’s location-related functionality. Normally, you should not need to make a class conform to the RouterDelegate
protocol or call any of its methods directly, but you would need to call this protocol’s methods if you implement a custom Router
class.
MapboxNavigationService
is the only concrete implementation of a router delegate. Implement the NavigationServiceDelegate
protocol instead to be notified when various significant events occur along the route tracked by a NavigationService
.
Seealso
MapboxNavigationServiceSeealso
NavigationServiceDelegate-
router(_:shouldRerouteFrom:)
Default implementationReturns whether the router should be allowed to calculate a new route.
If implemented, this method is called as soon as the router detects that the user is off the predetermined route. Implement this method to conditionally prevent rerouting. If this method returns
true
,router(_:willRerouteFrom:)
will be called immediately afterwards.Default Implementation
-
router(_:willRerouteFrom:)
Default implementationCalled immediately before the router calculates a new route.
This method is called after
router(_:shouldRerouteFrom:)
is called, and beforerouter(_:didRerouteAlong:)
is called.Default Implementation
-
router(_:shouldDiscard:)
Default implementationCalled when a location has been identified as unqualified to navigate on.
See
CLLocation.isQualified
for more information about what qualifies a location.- return: If
true
, the location is discarded and theRouter
will not consider it. Iffalse
, the location will not be thrown out.
Default Implementation
- return: If
-
router(_:didRerouteAlong:at:proactive:)
Default implementationCalled immediately after the router receives a new route.
This method is called after
router(_:willRerouteFrom:)
method is called.Default Implementation
-
router(_:didFailToRerouteWith:)
Default implementationCalled when the router fails to receive a new route.
This method is called after
router(_:willRerouteFrom:)
.Default Implementation
-
router(_:didUpdate:with:rawLocation:)
Default implementationCalled when the router updates the route progress model.
Default Implementation
-
router(_:didPassVisualInstructionPoint:routeProgress:)
Default implementationCalled when the router detects that the user has passed a point at which an instruction should be displayed.
Default Implementation
-
router(_:didPassSpokenInstructionPoint:routeProgress:)
Default implementationCalled when the router detects that the user has passed a point at which an instruction should be spoken.
Default Implementation
-
router(_:willArriveAt:after:distance:)
Default implementationCalled as the router approaches a waypoint.
This message is sent, once per progress update, as the user is approaching a waypoint. You can use this to cue UI, to do network pre-loading, etc.
Important
This method will likely be called several times as you approach a destination. If only one consumption of this method is desired, then usage of an internal flag is recommended.Default Implementation
-
router(_:didArriveAt:)
Default implementationCalled when the router arrives at a waypoint.
You can implement this method to prevent the router from automatically advancing to the next leg. For example, you can and show an interstitial sheet upon arrival and pause navigation by returning
false
, then continue the route when the user dismisses the sheet. If this method is unimplemented, the router automatically advances to the next leg when arriving at a waypoint.Postcondition
If you return false, you must manually advance to the next leg: obtain the value of therouteProgress
property, then increment theRouteProgress.legIndex
property.Default Implementation
-
router(_:shouldPreventReroutesWhenArrivingAt:)
Default implementationCalled when the router arrives at a waypoint.
You can implement this method to allow the router to continue check and reroute the user if needed. By default, the user will not be rerouted when arriving at a waypoint.
Default Implementation
-
routerShouldDisableBatteryMonitoring(_:)
Default implementationCalled when the router will disable battery monitoring.
Implementing this method will allow developers to change whether battery monitoring is disabled when the
Router
is deinited.Default Implementation