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(_: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: obtain the value of thenavigationServiceand itsNavigationService.routeProgressproperty, then increment theRouteProgress.legIndexproperty.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(_: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(_:willRerouteFrom:)Default implementationCalled immediately before the navigation view controller calculates a new route.
This method is called after
navigationViewController(_:shouldRerouteFrom:)is called, simultaneously with theNotification.Name.routeControllerWillReroutenotification being posted, and beforenavigationViewController(_:didRerouteAlong:)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(_:didRerouteAlong:)Default implementationCalled immediately after the navigation view controller receives a new route.
This method is called after
navigationViewController(_:willRerouteFrom:)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(_:didFailToRerouteWith:)Default implementationCalled when the navigation view controller fails to receive a new route.
This method is called after
navigationViewController(_:willRerouteFrom:)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(_:mainRouteStyleLayerWithIdentifier:source:)Default implementationReturns an
MGLStyleLayerthat determines the appearance of the main route line.If this method is unimplemented, the navigation view controller’s map view draws the route line using an
MGLLineStyleLayer.Default Implementation
UnimplementedLoggingprints a warning to standard output the first time this method is called.Declaration
Swift
func navigationViewController(_ navigationViewController: NavigationViewController, mainRouteStyleLayerWithIdentifier identifier: String, source: MGLSource) -> MGLStyleLayer? -
navigationViewController(_:mainRouteCasingStyleLayerWithIdentifier:source:)Default implementationReturns an
MGLStyleLayerthat determines the appearance of the casing around the main route line.If this method is unimplemented, the navigation view controller’s map view draws the casing for the main route line using an
MGLLineStyleLayer.Default Implementation
Declaration
Swift
func navigationViewController(_ navigationViewController: NavigationViewController, mainRouteCasingStyleLayerWithIdentifier identifier: String, source: MGLSource) -> MGLStyleLayer? -
navigationViewController(_:alternativeRouteStyleLayerWithIdentifier:source:)Default implementationReturns an
MGLStyleLayerthat determines the appearance of alternative route lines.If this method is unimplemented, the navigation view controller’s map view draws the alternative route lines using an
MGLLineStyleLayer.Default Implementation
Declaration
Swift
func navigationViewController(_ navigationViewController: NavigationViewController, alternativeRouteStyleLayerWithIdentifier identifier: String, source: MGLSource) -> MGLStyleLayer? -
navigationViewController(_:alternativeRouteCasingStyleLayerWithIdentifier:source:)Default implementationReturns an
MGLStyleLayerthat determines the appearance of the casing around the alternative route lines.If this method is unimplemented, the navigation view controller’s map view draws the casing for the alternative route lines using an
MGLLineStyleLayer.Default Implementation
Declaration
Swift
func navigationViewController(_ navigationViewController: NavigationViewController, alternativeRouteCasingStyleLayerWithIdentifier identifier: String, source: MGLSource) -> MGLStyleLayer? -
navigationViewController(_:shapeFor:)Default implementationReturns an
MGLShapethat represents the path of the route line.If this method is unimplemented, the navigation view controller’s map view represents the route line using an
MGLPolylineFeaturebased onroute’scoordinatesproperty.Default Implementation
UnimplementedLoggingprints a warning to standard output the first time this method is called.Declaration
Swift
func navigationViewController(_ navigationViewController: NavigationViewController, shapeFor routes: [Route]) -> MGLShape? -
navigationViewController(_:simplifiedShapeFor:)Default implementationReturns an
MGLShapethat represents the path of the route line’s casing.If this method is unimplemented, the navigation view controller’s map view represents the route line’s casing using an
MGLPolylineFeatureidentical to the one returned bynavigationViewController(_:shapeFor:).Default Implementation
UnimplementedLoggingprints a warning to standard output the first time this method is called.Declaration
Swift
func navigationViewController(_ navigationViewController: NavigationViewController, simplifiedShapeFor route: Route) -> MGLShape? -
navigationViewController(_:waypointStyleLayerWithIdentifier:source:)Default implementationReturns an
MGLStyleLayerthat 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(_:waypointSymbolStyleLayerWithIdentifier:source:).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, waypointStyleLayerWithIdentifier identifier: String, source: MGLSource) -> MGLStyleLayer? -
navigationViewController(_:waypointSymbolStyleLayerWithIdentifier:source:)Default implementationReturns an
MGLStyleLayerthat 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(_:waypointStyleLayerWithIdentifier:source:).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, waypointSymbolStyleLayerWithIdentifier identifier: String, source: MGLSource) -> MGLStyleLayer? -
navigationViewController(_:shapeFor:legIndex:)Default implementationReturns an
MGLShapethat represents the destination waypoints along the route (that is, excluding the origin).If this method is unimplemented, the navigation map view represents the route waypoints using
navigationViewController(_:shapeFor:legIndex:).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) -> MGLShape? -
navigationViewController(_:didSelect:)Default implementationCalled when the user taps to select a route on the navigation view controller’s map view.
Default Implementation
UnimplementedLoggingprints a warning to standard output the first time this method is called.Declaration
Swift
func navigationViewController(_ navigationViewController: NavigationViewController, didSelect route: Route)Parameters
navigationViewControllerThe navigation view controller presenting the route that the user selected.
routeThe route on the map that the user selected.
-
navigationViewController(_:mapViewUserAnchorPoint:)Default implementationReturns the center point of the user course view in screen coordinates relative to the map view.
Default Implementation
UnimplementedLoggingprints a warning to standard output the first time this method is called.Declaration
Swift
func navigationViewController(_ navigationViewController: NavigationViewController, mapViewUserAnchorPoint mapView: NavigationMapView) -> CGPoint -
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(_: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.
Install in Dash
NavigationViewControllerDelegate Protocol Reference