NavigationViewControllerDelegate
public protocol NavigationViewControllerDelegate : VisualInstructionDelegate
The NavigationViewControllerDelegate protocol provides methods for configuring the map view shown by a NavigationViewController and responding to the cancellation of a navigation session.
For convenience, several location-related methods in the NavigationServiceDelegate protocol have corresponding methods in this protocol.
-
navigationViewControllerDidDismiss(_:byCanceling:)Default implementationCalled when the navigation view controller is dismissed, such as when the user ends a trip.
Default Implementation
UnimplementedLoggingprints a warning to standard output the first time this method is called.Declaration
Swift
func navigationViewControllerDidDismiss(_ navigationViewController: NavigationViewController, byCanceling canceled: Bool)Parameters
navigationViewControllerThe navigation view controller that was dismissed.
canceledTrue if the user dismissed the navigation view controller by tapping the Cancel button; false if the navigation view controller dismissed by some other means.
-
navigationViewController(_:didUpdate:with:rawLocation:)Default implementationCalled when movement of the user updates the route progress model.
Default Implementation
UnimplementedLoggingprints a warning to standard output the first time this method is called.Declaration
Swift
func navigationViewController(_ navigationViewController: NavigationViewController, didUpdate progress: RouteProgress, with location: CLLocation, rawLocation: CLLocation)Parameters
navigationViewControllerThe ViewController 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.
-
navigationViewController(_:didAdd:pointAnnotationManager:)Default implementationTells the receiver that the final destination
PointAnnotationwas added to theNavigationViewController.Default Implementation
UnimplementedLoggingprints a warning to standard output the first time this method is called.Declaration
Swift
func navigationViewController(_ navigationViewController: NavigationViewController, didAdd finalDestinationAnnotation: PointAnnotation, pointAnnotationManager: PointAnnotationManager)Parameters
navigationViewControllerThe
NavigationViewControllerobject.finalDestinationAnnotationThe point annotation that was added to the map view.
pointAnnotationManagerThe object that manages the point annotation in the map view.
-
navigationViewController(_:willArriveAt:after:distance:)Default implementationCalled as the user 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.
Note
This method will likely be called several times as you approach a destination. To respond to the user’s arrival only once, your delegate can define a property that keeps track of whether this method has already been called for the given waypoint.Default Implementation
UnimplementedLoggingprints a warning to standard output the first time this method is called.Declaration
Swift
func navigationViewController(_ navigationViewController: NavigationViewController, willArriveAt waypoint: Waypoint, after remainingTimeInterval: TimeInterval, distance: CLLocationDistance)Parameters
navigationViewControllerThe Navigation VC that is detecting the users’ approach.
waypointThe waypoint that the service is arriving at.
remainingTimeIntervalThe estimated number of seconds until arrival.
distanceThe current distance from the waypoint, in meters.
-
navigationViewController(_:didArriveAt:)Default implementationCalled when the user arrives at the destination waypoint for a route leg.
This method is called when the navigation view controller arrives at the waypoint. You can implement this method to prevent the navigation view controller 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 navigation view controller automatically advances to the next leg when arriving at a waypoint.Postcondition
If you returnfalsewithin this method, you must manually advance to the next leg using theRouter.advanceLegIndex(completionHandler:)method. ObtainRoutervia theNavigationViewController.navigationServiceandNavigationService.routerproperties.Default Implementation
UnimplementedLoggingprints a warning to standard output the first time this method is called.Declaration
Swift
func navigationViewController(_ navigationViewController: NavigationViewController, didArriveAt waypoint: Waypoint) -> BoolParameters
navigationViewControllerThe navigation view controller that has arrived at a waypoint.
waypointThe waypoint that the user has arrived at.
Return Value
True to automatically advance to the next leg, or false to remain on the now completed leg.
-
navigationViewController(_:didSelect:)Default implementationTells the receiver that a waypoint was selected.
Default Implementation
UnimplementedLoggingprints a warning to standard output the first time this method is called.Declaration
Swift
func navigationViewController(_ navigationViewController: NavigationViewController, didSelect waypoint: Waypoint)Parameters
navigationViewControllerThe
NavigationViewControllerobject.waypointThe waypoint that was selected.
-
navigationViewController(_:shouldRerouteFrom:)Default implementationReturns whether the navigation view controller should be allowed to calculate a new route.
If implemented, this method is called as soon as the navigation view controller detects that the user is off the predetermined route. Implement this method to conditionally prevent rerouting. If this method returns
true,navigationViewController(_:willRerouteFrom:)will be called immediately afterwards.Default Implementation
UnimplementedLoggingprints a warning to standard output the first time this method is called.Declaration
Swift
func navigationViewController(_ navigationViewController: NavigationViewController, shouldRerouteFrom location: CLLocation) -> BoolParameters
navigationViewControllerThe navigation view controller that has detected the need to calculate a new route.
locationThe user’s current location.
Return Value
True to allow the navigation view controller to calculate a new route; false to keep tracking the current route.
-
navigationViewController(_: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 navigation view controller 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
Swift
func navigationViewController(_ navigationViewController: NavigationViewController, shouldProactivelyRerouteFrom location: CLLocation, to route: Route, completion: @escaping () -> Void)Parameters
navigationViewControllerThe navigation view controller that has detected faster new route
locationThe user’s current location.
routeThe route found.
completionCompletion to be called to allow the navigation view controller to apply a new route; Ignoring calling the completion will ignore the faster route aswell.
-
navigationViewController(_:shouldPreventReroutesWhenArrivingAt:)Default implementationCalled when the user arrives at a waypoint.
Return false to continue checking if reroute is needed. By default, the user will not be rerouted when arriving at a waypoint.
Default Implementation
UnimplementedLoggingprints a warning to standard output the first time this method is called.Declaration
Swift
func navigationViewController(_ navigationViewController: NavigationViewController, shouldPreventReroutesWhenArrivingAt waypoint: Waypoint) -> BoolParameters
navigationViewControllerThe navigation view controller that has detected the need to calculate a new route.
waypointThe waypoint that the controller has arrived at.
Return Value
True to prevent reroutes.
-
navigationViewController(_:willRerouteFrom:)Default implementationCalled immediately before the navigation view controller calculates a new route.
This method also allows customizing the rerouting by providing custom
RouteResponse. SDK will then treat it as if it was fetched as usual and apply as a reroute.Note
Multiple method calls will not interrupt the first ongoing request.This method is called after
navigationViewController(_:shouldRerouteFrom:)is called, simultaneously with theNotification.Name.routeControllerWillReroutenotification being posted, and beforenavigationViewController(_:modifiedOptionsForReroute:)is called.Default Implementation
UnimplementedLoggingprints a warning to standard output the first time this method is called.Declaration
Swift
func navigationViewController(_ navigationViewController: NavigationViewController, willRerouteFrom location: CLLocation?)Parameters
navigationViewControllerThe navigation view controller that will calculate a new route.
locationThe user’s current location.
-
navigationViewController(_:modifiedOptionsForReroute:)Default implementationWhen reroute is happening, navigation view controller suggests to customize the
RouteOptionsused to calculate new route.This method is called after
navigationViewController(_:willRerouteFrom:)is called, and beforenavigationViewController(_:didRerouteAlong:)is called. This method is not called on proactive rerouting.Default implementation does no modifications.
Default Implementation
UnimplementedLoggingprints a warning to standard output the first time this method is called.Declaration
Swift
func navigationViewController(_ navigationViewController: NavigationViewController, modifiedOptionsForReroute options: RouteOptions) -> RouteOptionsParameters
navigationViewControllerThe navigation view controller that will calculate a new route.
optionsOriginal
RouteOptions.Return Value
Modified
RouteOptions. -
navigationViewController(_:didRerouteAlong:)Default implementationCalled immediately after the navigation view controller receives a new route.
This method is called after
navigationViewController(_:modifiedOptionsForReroute:)and simultaneously with theNotification.Name.routeControllerDidReroutenotification being posted.Default Implementation
UnimplementedLoggingprints a warning to standard output the first time this method is called.Declaration
Swift
func navigationViewController(_ navigationViewController: NavigationViewController, didRerouteAlong route: Route)Parameters
navigationViewControllerThe navigation view controller that has calculated a new route.
routeThe new route.
-
navigationViewController(_:didUpdateAlternatives:removedAlternatives:)Default implementationCalled when navigation view controller has detected a change in alternative routes list.
Default Implementation
UnimplementedLoggingprints a warning to standard output the first time this method is called.Declaration
Swift
func navigationViewController(_ navigationViewController: NavigationViewController, didUpdateAlternatives updatedAlternatives: [AlternativeRoute], removedAlternatives: [AlternativeRoute])Parameters
navigationViewControllerThe navigation view controller reporting an update.
updatedAlternativesArray of actual alternative routes.
removedAlternativesArray of alternative routes which are no longer actual.
-
navigationViewController(_:didFailToUpdateAlternatives:)Default implementationCalled when navigation view controller has failed to change alternative routes list.
Default Implementation
UnimplementedLoggingprints a warning to standard output the first time this method is called.Declaration
Swift
func navigationViewController(_ navigationViewController: NavigationViewController, didFailToUpdateAlternatives error: AlternativeRouteError)Parameters
navigationViewControllerThe navigation view controller reporting an update.
errorAn error occured.
-
navigationViewController(_:didSwitchToCoincidentOnlineRoute:)Default implementationCalled when navigation view controller has automatically switched to the coincide online route.
Default Implementation
UnimplementedLoggingprints a warning to standard output the first time this method is called.Declaration
Swift
func navigationViewController(_ navigationViewController: NavigationViewController, didSwitchToCoincidentOnlineRoute coincideRoute: Route)Parameters
navigationViewControllerThe navigation view controller reporting an update.
coincideRouteA route taken.
-
navigationViewController(_:willTakeAlternativeRoute:at:)Default implementationCalled when navigation view controller has detected user taking an alternative route.
This method is called before updating main route.
Default Implementation
UnimplementedLoggingprints a warning to standard output the first time this method is called.Declaration
Swift
func navigationViewController(_ navigationViewController: NavigationViewController, willTakeAlternativeRoute route: Route, at location: CLLocation?)Parameters
navigationViewControllerThe navigation view controller that has detected turning to the alternative.
routeThe alternative route which will be taken as new main.
locationThe user’s current location.
-
navigationViewController(_:didTakeAlternativeRouteAt:)Default implementationCalled when navigation view controller has finished switching to an alternative route
This method is called after
navigationViewController(_:willTakeAlternativeRoute:)Default Implementation
UnimplementedLoggingprints a warning to standard output the first time this method is called.Declaration
Swift
func navigationViewController(_ navigationViewController: NavigationViewController, didTakeAlternativeRouteAt location: CLLocation?)Parameters
navigationViewControllerThe navigation view controller that switched to the alternative.
locationThe user’s current location.
-
navigationViewController(_:didFailToTakeAlternativeRouteAt:)Default implementationCalled when navigation view controller has failed to take an alternative route.
This method is called after
navigationViewController(_:willTakeAlternativeRoute:).This call would indicate that something went wrong during setting new main route.
Default Implementation
UnimplementedLoggingprints a warning to standard output the first time this method is called.Declaration
Swift
func navigationViewController(_ navigationViewController: NavigationViewController, didFailToTakeAlternativeRouteAt location: CLLocation?)Parameters
navigationViewControllerThe navigation view controller which tried to switch to the alternative.
locationThe user’s current location.
-
Tells the receiver that the user has selected a continuous alternative route by interacting with the map view.
Continuous alternatives are all non-primary routes, reported during the navigation session.
Declaration
Swift
func navigationViewController(_ navigationViewController: NavigationViewController, didSelect continuousAlternative: AlternativeRoute)Parameters
navigationViewControllerThe
NavigationViewControllerobject.continuousAlternativeThe route that was selected.
-
navigationViewController(_:didFailToRerouteWith:)Default implementationCalled when the navigation view controller fails to receive a new route.
This method is called after
navigationViewController(_:modifiedOptionsForReroute:)and simultaneously with theNotification.Name.routeControllerDidFailToReroutenotification being posted.Default Implementation
UnimplementedLoggingprints a warning to standard output the first time this method is called.Declaration
Swift
func navigationViewController(_ navigationViewController: NavigationViewController, didFailToRerouteWith error: Error)Parameters
navigationViewControllerThe navigation view controller that has calculated a new route.
errorAn error raised during the process of obtaining a new route.
-
navigationViewController(_:didRefresh:)Default implementationCalled immediately after the navigation view controller refreshes the route.
This method is called simultaneously with the
Notification.Name.routeControllerDidRefreshRoutenotification being posted.Default Implementation
UnimplementedLoggingprints a warning to standard output the first time this method is called.Declaration
Swift
func navigationViewController(_ navigationViewController: NavigationViewController, didRefresh routeProgress: RouteProgress)Parameters
navigationViewControllerThe navigation view controller that has refreshed the route.
routeProgressThe updated route progress with the refreshed route.
-
navigationViewController(_:routeLineLayerWithIdentifier:sourceIdentifier:)Default implementationReturns an
LineLayerthat determines the appearance of the route line.If this method is not implemented, the navigation view controller’s map view draws the route line using default
LineLayer.Default Implementation
UnimplementedLoggingprints a warning to standard output the first time this method is called.Declaration
Swift
func navigationViewController(_ navigationViewController: NavigationViewController, routeLineLayerWithIdentifier identifier: String, sourceIdentifier: String) -> LineLayer?Parameters
navigationViewControllerThe
NavigationViewControllerobject, on surface of which route line is drawn.identifierThe
LineLayeridentifier.sourceIdentifierIdentifier of the source, which contains the route data that this method would style.
Return Value
A
LineLayerthat is applied to the route line. -
navigationViewController(_:routeCasingLineLayerWithIdentifier:sourceIdentifier:)Default implementationReturns an
LineLayerthat determines the appearance of the casing around the route line.If this method is not implemented, the navigation view controller’s map view draws the casing for the route line using default
LineLayer.Default Implementation
UnimplementedLoggingprints a warning to standard output the first time this method is called.Declaration
Swift
func navigationViewController(_ navigationViewController: NavigationViewController, routeCasingLineLayerWithIdentifier identifier: String, sourceIdentifier: String) -> LineLayer?Parameters
navigationViewControllerThe
NavigationViewControllerobject, on surface of which route line is drawn.identifierThe
LineLayeridentifier.sourceIdentifierIdentifier of the source, which contains the route data that this method would style.
Return Value
A
LineLayerthat is applied as a casing around the route line. -
navigationViewController(_:routeRestrictedAreasLineLayerWithIdentifier:sourceIdentifier:)Default implementationReturns an
LineLayerthat determines the appearance of the restricted areas portions of the route line.If this method is not implemented, the navigation view controller’s map view draws the areas using default
LineLayer.Default Implementation
UnimplementedLoggingprints a warning to standard output the first time this method is called.Declaration
Swift
func navigationViewController(_ navigationViewController: NavigationViewController, routeRestrictedAreasLineLayerWithIdentifier identifier: String, sourceIdentifier: String) -> LineLayer?Parameters
navigationViewControllerThe
NavigationViewControllerobject, on surface of which route line is drawn.identifierThe
LineLayeridentifier.sourceIdentifierIdentifier of the source, which contains the route data that this method would style.
Return Value
A
LineLayerthat is applied as restricted areas on the route line. -
navigationViewController(_:willAdd:)Default implementationAsks the receiver to adjust the default layer which will be added to the map view and return a
Layer.If this method is not implemented, the navigation view controller’s map view draws the default
layer.Default Implementation
UnimplementedLoggingprints a warning to standard output the first time this method is called.Declaration
Swift
func navigationViewController(_ navigationViewController: NavigationViewController, willAdd layer: Layer) -> Layer?Parameters
navigationViewControllerThe
NavigationViewControllerobject, on surface of which route line is drawn.layerA default
Layergenerated by the navigationViewController.Return Value
A
Layerafter adjusted and will be added to the navigation view controller’s map view byMapboxNavigation. -
navigationViewController(_:waypointCircleLayerWithIdentifier:sourceIdentifier:)Default implementationReturns an
CircleLayerthat marks the location of each destination along the route when there are multiple destinations. The returned layer is added to the map below the layer returned bynavigationViewController(_:waypointSymbolLayerWithIdentifier:sourceIdentifier:).If this method is unimplemented, the navigation view controller’s map view marks each destination waypoint with a circle.
Default Implementation
UnimplementedLoggingprints a warning to standard output the first time this method is called.Declaration
Swift
func navigationViewController(_ navigationViewController: NavigationViewController, waypointCircleLayerWithIdentifier identifier: String, sourceIdentifier: String) -> CircleLayer?Parameters
navigationViewControllerThe
NavigationViewControllerobject.identifierThe
CircleLayeridentifier.sourceIdentifierIdentifier of the source, which contains the waypoint data that this method would style.
Return Value
A
CircleLayerthat the map applies to all waypoints. -
navigationViewController(_:waypointSymbolLayerWithIdentifier:sourceIdentifier:)Default implementationReturns a
SymbolLayerthat places an identifying symbol on each destination along the route when there are multiple destinations. The returned layer is added to the map above the layer returned bynavigationViewController(_:waypointCircleLayerWithIdentifier:sourceIdentifier:).If this method is unimplemented, the navigation view controller’s map view labels each destination waypoint with a number, starting with 1 at the first destination, 2 at the second destination, and so on.
Default Implementation
UnimplementedLoggingprints a warning to standard output the first time this method is called.Declaration
Swift
func navigationViewController(_ navigationViewController: NavigationViewController, waypointSymbolLayerWithIdentifier identifier: String, sourceIdentifier: String) -> SymbolLayer?Parameters
navigationViewControllerThe
NavigationViewControllerobject.identifierThe
SymbolLayeridentifier.sourceIdentifierIdentifier of the source, which contains the waypoint data that this method would style.
Return Value
A
SymbolLayerthat the map applies to all waypoint symbols. -
navigationViewController(_:shapeFor:legIndex:)Default implementationReturns a
FeatureCollectionthat represents the destination waypoints along the route (that is, excluding the origin).If this method is unimplemented, the navigation view controller’s map view draws the waypoints using default
FeatureCollection.Default Implementation
UnimplementedLoggingprints a warning to standard output the first time this method is called.Declaration
Swift
func navigationViewController(_ navigationViewController: NavigationViewController, shapeFor waypoints: [Waypoint], legIndex: Int) -> FeatureCollection?Parameters
navigationViewControllerThe
NavigationViewControllerobject.waypointsThe waypoints to be displayed on the map.
legIndexReturn Value
Optionally, a
FeatureCollectionthat defines the shape of the waypoint, ornilto use default behavior. -
navigationViewController(_:roadNameAt:)Default implementationCalled to allow the delegate to customize the contents of the road name label that is displayed towards the bottom of the map view.
This method is called on each location update. By default, the label displays the name of the road the user is currently traveling on.
Default Implementation
UnimplementedLoggingprints a warning to standard output the first time this method is called.Declaration
Swift
func navigationViewController(_ navigationViewController: NavigationViewController, roadNameAt location: CLLocation) -> String?Parameters
navigationViewControllerThe navigation view controller that will display the road name.
locationThe user’s current location.
Return Value
The road name to display in the label, or nil to hide the label.
-
navigationViewController(_:shouldDiscard:)Default implementationAllows the delegate to decide whether to ignore a location update.
This method is called on every location update. By default, the navigation view controller ignores certain location updates that appear to be unreliable, as determined by the
CLLocation.isQualifiedproperty.Default Implementation
UnimplementedLoggingprints a warning to standard output the first time this method is called.Declaration
Swift
func navigationViewController(_ navigationViewController: NavigationViewController, shouldDiscard location: CLLocation) -> BoolParameters
navigationViewControllerThe navigation view controller that discarded the location.
locationThe location that will be discarded.
Return Value
If
true, the location is discarded and theNavigationViewControllerwill not consider it. Iffalse, the location will not be thrown out. -
navigationViewController(_:didSubmitArrivalFeedback:)Default implementationCalled to notify that the user submitted the end of route feedback.
Default Implementation
UnimplementedLoggingprints a warning to standard output the first time this method is called.Declaration
Swift
func navigationViewController(_ navigationViewController: NavigationViewController, didSubmitArrivalFeedback feedback: EndOfRouteFeedback)Parameters
navigationViewControllerThe
NavigationViewControllerobject.feedbackThe
EndOfRouteFeedbackthat was submitted by the user.
Install in Dash
NavigationViewControllerDelegate Protocol Reference