RouterDelegate
public protocol RouterDelegate : AnyObject, UnimplementedLogging
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
Declaration
Swift
func router(_ router: Router, shouldRerouteFrom location: CLLocation) -> BoolParameters
routerThe router that has detected the need to calculate a new route.
locationThe user’s current location.
Return Value
True to allow the router to calculate a new route; false to keep tracking the current route.
-
router(_:shouldProactivelyRerouteFrom:to:completion:)Default implementationAsks permission to proceed with found proactive reroute and apply it as main route.
If implemented, this method is called as soon as the router detects route faster than the current one. This only happens if
Router.reroutesProactivelyis set totrue(default). Calling providedcompletionresults in new route to be set, without triggering usual rerouting delegate methods.Default Implementation
Declaration
Parameters
routerThe router that has detected faster new route
locationThe user’s current location.
routeThe route found.
completionCompletion to be called to allow the router to apply a new route; Ignoring calling the completion will ignore the faster route aswell.
-
router(_:willRerouteFrom:)Default implementationCalled immediately before the router calculates a new route.
This method is called after
router(_:shouldRerouteFrom:)is called, and beforerouter(_:modifiedOptionsForReroute:)is called.Default Implementation
Declaration
Swift
func router(_ router: Router, willRerouteFrom location: CLLocation)Parameters
routerThe router that will calculate a new route.
locationThe user’s current location.
-
router(_:modifiedOptionsForReroute:)Default implementationWhen reroute is happening, router suggests to customize the
RouteOptionsused to calculate new route.This method is called after
router(_:willRerouteFrom:)is called, and beforerouter(_:didRerouteAlong:)is called. This method is not called on proactive rerouting.Default implementation does no modifications.
Default Implementation
Declaration
Swift
func router(_ router: Router, modifiedOptionsForReroute options: RouteOptions) -> RouteOptionsParameters
routerThe router that will calculate a new route.
optionsOriginal
RouteOptions.Return Value
Modified
RouteOptions. -
router(_:shouldDiscard:)Default implementationCalled when a location has been identified as unqualified to navigate on.
See
CLLocation.isQualifiedfor more information about what qualifies a location.- return: If
true, the location is discarded and theRouterwill not consider it. Iffalse, the location will not be thrown out.
Default Implementation
Declaration
Swift
func router(_ router: Router, shouldDiscard location: CLLocation) -> BoolParameters
routerThe router that discarded the location.
locationThe location that will be discarded.
- return: If
-
router(_:didRerouteAlong:at:proactive:)Default implementationCalled immediately after the router receives a new route.
This method is called after
router(_:modifiedOptionsForReroute:)method is called.Default Implementation
Declaration
Parameters
routerThe router that has calculated a new route.
routeThe new route.
-
router(_:didUpdateAlternatives:removedAlternatives:)Default implementationCalled when router has detected a change in alternative routes list.
Note
LegacyRouteControllerwill never report alternative routes updates.Default Implementation
Declaration
Swift
func router(_ router: Router, didUpdateAlternatives updatedAlternatives: [AlternativeRoute], removedAlternatives: [AlternativeRoute])Parameters
routerThe router reporting an update.
updatedAlternativesArray of actual alternative routes.
removedAlternativesArray of alternative routes which are no longer actual.
-
router(_:didFailToUpdateAlternatives:)Default implementationCalled when router has failed to change alternative routes list.
Note
LegacyRouteControllerwill never report alternative routes updates.Default Implementation
Declaration
Swift
func router(_ router: Router, didFailToUpdateAlternatives error: AlternativeRouteError)Parameters
routerThe router reporting an update.
errorAn error occured.
-
router(_:willTakeAlternativeRoute:at:)Default implementationCalled when router has detected user taking an alternative route.
This method is called before updating router’s main route.
LegacyRouteControllernever calls this method, because it cannot generate routes on the device.Default Implementation
Declaration
Parameters
routerThe router that has detected turning to the alternative.
routeThe alternative route which will be taken as new main.
locationThe user’s current location.
-
router(_:didTakeAlternativeRouteAt:)Default implementationCalled when router has finished switching to an alternative route
This method is called after
router(_:willTakeAlternativeRoute:)Note
LegacyRouteControllerwill never report alternative routes updates.Default Implementation
Declaration
Swift
func router(_ router: Router, didTakeAlternativeRouteAt location: CLLocation?)Parameters
routerThe router that switched to the alternative.
locationThe user’s current location.
-
router(_:didFailToTakeAlternativeRouteAt:)Default implementationCalled when router has failed to take an alternative route.
This method is called after
router(_:willTakeAlternativeRoute:).This call would indicate that something went wrong during setting new main route.
Note
LegacyRouteControllerwill never report alternative routes updates.Default Implementation
Declaration
Swift
func router(_ router: Router, didFailToTakeAlternativeRouteAt location: CLLocation?)Parameters
routerThe router which tried to switch to the alternative.
locationThe user’s current location.
-
router(_:didSwitchToCoincidentOnlineRoute:)Default implementationCalled when router has automatically switched to the coincide online route.
Note
LegacyRouteControllerwill never do that.Default Implementation
Declaration
Parameters
routerThe router reporting an update.
coincideRouteA route taken.
-
router(_:didFailToRerouteWith:)Default implementationCalled when the router fails to receive a new route.
This method is called after
router(_:modifiedOptionsForReroute:).Default Implementation
Declaration
Swift
func router(_ router: Router, didFailToRerouteWith error: Error)Parameters
routerThe router that has calculated a new route.
errorAn error raised during the process of obtaining a new route.
-
Called immediately after the router refreshes the route.
Declaration
Swift
func router(_ router: Router, didRefresh routeProgress: RouteProgress)Parameters
routerThe router that has refreshed the route.
routeProgressThe route progress updated with the refreshed route.
-
router(_:didUpdate:with:rawLocation:)Default implementationCalled when the router updates the route progress model.
Default Implementation
Declaration
Swift
func router(_ router: Router, didUpdate progress: RouteProgress, with location: CLLocation, rawLocation: CLLocation)Parameters
routerThe router that received the new locations.
progressthe RouteProgress model that was updated.
locationthe guaranteed location, possibly snapped, associated with the progress update.
rawLocationthe raw location, from the location manager, associated with the progress update.
-
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
Declaration
Parameters
routerThe router that has arrived at a waypoint.
waypointThe waypoint that the controller has arrived at.
Return Value
True to prevent the router from checking if the user should be rerouted.
-
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
Declaration
Parameters
routerThe router that is detecting the destination approach.
waypointThe waypoint that the service is arriving at.
remainingTimeIntervalThe estimated number of seconds until arrival.
distanceThe current distance from the waypoint, in meters.
-
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 usingRouter.advanceLegIndex(completionHandler:)method.Default Implementation
Parameters
routerThe router that has arrived at a waypoint.
waypointThe waypoint that the controller has arrived at.
Return Value
True to advance to the next leg, if any, or false to remain on the completed leg.
-
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
Declaration
Swift
func router(_ router: Router, didPassVisualInstructionPoint instruction: VisualInstructionBanner, routeProgress: RouteProgress)Parameters
routerThe router that passed the instruction point.
instructionThe instruction to be presented.
routeProgressThe route progress object that the router is updating.
-
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
Declaration
Swift
func router(_ router: Router, didPassSpokenInstructionPoint instruction: SpokenInstruction, routeProgress: RouteProgress)Parameters
routerThe router that passed the instruction point.
instructionThe instruction to be spoken.
routeProgressThe route progress object that the router is updating.
-
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
Routeris deinited.Default Implementation
Declaration
Swift
func routerShouldDisableBatteryMonitoring(_ router: Router) -> BoolParameters
routerThe router that will change the state of battery monitoring.
Return Value
A bool indicating whether to disable battery monitoring when the RouteController is deinited.
Install in Dash
RouterDelegate Protocol Reference