NavigationViewControllerDelegate

@objc(MBNavigationViewControllerDelegate)
public protocol NavigationViewControllerDelegate : VisualInstructionDelegate

The NavigationViewControllerDelegate provides methods for configuring the map view shown by a NavigationViewController and responding to the cancellation of a navigation session.

  • Called when the navigation view controller is dismissed, such as when the user ends a trip.

    Declaration

    Swift

    @objc
    optional func navigationViewControllerDidDismiss(_ navigationViewController: NavigationViewController, byCanceling canceled: Bool)

    Parameters

    navigationViewController

    The navigation view controller that was dismissed.

    canceled

    True if the user dismissed the navigation view controller by tapping the Cancel button; false if the navigation view controller dismissed by some other means.

  • Called 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 return false within this method, you must manually advance to the next leg: obtain the value of the routeController and its RouteController.routeProgress property, then increment the RouteProgress.legIndex property.

    Declaration

    Swift

    @objc(navigationViewController:didArriveAtWaypoint:)
    optional func navigationViewController(_ navigationViewController: NavigationViewController, didArriveAt waypoint: Waypoint) -> Bool

    Parameters

    navigationViewController

    The navigation view controller that has arrived at a waypoint.

    waypoint

    The 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.

  • Returns 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.

    Declaration

    Swift

    @objc(navigationViewController:shouldRerouteFromLocation:)
    optional func navigationViewController(_ navigationViewController: NavigationViewController, shouldRerouteFrom location: CLLocation) -> Bool

    Parameters

    navigationViewController

    The navigation view controller that has detected the need to calculate a new route.

    location

    The 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.

  • Called immediately before the navigation view controller calculates a new route.

    This method is called after navigationViewController(_:shouldRerouteFrom:) is called, simultaneously with the RouteControllerWillReroute notification being posted, and before navigationViewController(_:didRerouteAlong:) is called.

    Declaration

    Swift

    @objc(navigationViewController:willRerouteFromLocation:)
    optional func navigationViewController(_ navigationViewController: NavigationViewController, willRerouteFrom location: CLLocation)

    Parameters

    navigationViewController

    The navigation view controller that will calculate a new route.

    location

    The user’s current location.

  • Called immediately after the navigation view controller receives a new route.

    This method is called after navigationViewController(_:willRerouteFrom:) and simultaneously with the RouteControllerDidReroute notification being posted.

    Declaration

    Swift

    @objc(navigationViewController:didRerouteAlongRoute:)
    optional func navigationViewController(_ navigationViewController: NavigationViewController, didRerouteAlong route: Route)

    Parameters

    navigationViewController

    The navigation view controller that has calculated a new route.

    route

    The new route.

  • Called when the navigation view controller fails to receive a new route.

    This method is called after navigationViewController(_:willRerouteFrom:) and simultaneously with the RouteControllerDidFailToReroute notification being posted.

    Declaration

    Swift

    @objc(navigationViewController:didFailToRerouteWithError:)
    optional func navigationViewController(_ navigationViewController: NavigationViewController, didFailToRerouteWith error: Error)

    Parameters

    navigationViewController

    The navigation view controller that has calculated a new route.

    error

    An error raised during the process of obtaining a new route.

  • Returns an MGLStyleLayer that determines the appearance of the route line.

    If this method is unimplemented, the navigation view controller’s map view draws the route line using an MGLLineStyleLayer.

    Declaration

    Swift

    @objc
    optional func navigationViewController(_ navigationViewController: NavigationViewController, routeStyleLayerWithIdentifier identifier: String, source: MGLSource) -> MGLStyleLayer?
  • Returns an MGLStyleLayer that determines the appearance of the route line’s casing.

    If this method is unimplemented, the navigation view controller’s map view draws the route line’s casing using an MGLLineStyleLayer whose width is greater than that of the style layer returned by navigationViewController(_:routeStyleLayerWithIdentifier:source:).

    Declaration

    Swift

    @objc
    optional func navigationViewController(_ navigationViewController: NavigationViewController, routeCasingStyleLayerWithIdentifier identifier: String, source: MGLSource) -> MGLStyleLayer?
  • Returns an MGLShape that 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 MGLPolylineFeature based on route’s coordinates property.

    Declaration

    Swift

    @objc(navigationViewController:shapeForRoutes:)
    optional func navigationViewController(_ navigationViewController: NavigationViewController, shapeFor routes: [Route]) -> MGLShape?
  • Returns an MGLShape that 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 MGLPolylineFeature identical to the one returned by navigationViewController(_:shapeFor:).

    Declaration

    Swift

    @objc(navigationViewController:simplifiedShapeForRoute:)
    optional func navigationViewController(_ navigationViewController: NavigationViewController, simplifiedShapeFor route: Route) -> MGLShape?
  • Returns an MGLShape that 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:).

    Declaration

    Swift

    @objc(navigationViewController:shapeForWaypoints:legIndex:)
    optional func navigationViewController(_ navigationViewController: NavigationViewController, shapeFor waypoints: [Waypoint], legIndex: Int) -> MGLShape?
  • Called when the user taps to select a route on the navigation view controller’s map view.

    Declaration

    Swift

    @objc(navigationViewController:didSelectRoute:)
    optional func navigationViewController(_ navigationViewController: NavigationViewController, didSelect route: Route)

    Parameters

    navigationViewController

    The navigation view controller presenting the route that the user selected.

    route

    The route on the map that the user selected.

  • Return an MGLAnnotationImage that represents the destination marker.

    If this method is unimplemented, the navigation view controller’s map view will represent the destination annotation with the default marker.

    Declaration

    Swift

    @objc(navigationViewController:imageForAnnotation:)
    optional func navigationViewController(_ navigationViewController: NavigationViewController, imageFor annotation: MGLAnnotation) -> MGLAnnotationImage?
  • Returns a view object to mark the given point annotation object on the map.

    The user location annotation view can also be customized via this method. When annotation is an instance of MGLUserLocation, return an instance of MGLUserLocationAnnotationView (or a subclass thereof). Note that when NavigationMapView.tracksUserCourse is set to true, the navigation view controller’s map view uses a distinct user course view; to customize it, set the NavigationMapView.userCourseView property of the map view stored by the NavigationViewController.mapView property.

    Declaration

    Swift

    @objc(navigationViewController:viewForAnnotation:)
    optional func navigationViewController(_ navigationViewController: NavigationViewController, viewFor annotation: MGLAnnotation) -> MGLAnnotationView?
  • Called when the user opens the feedback form.

    Declaration

    Swift

    @objc
    optional func navigationViewControllerDidOpenFeedback(_ viewController: NavigationViewController)
  • Called when the user dismisses the feedback form.

    Declaration

    Swift

    @objc
    optional func navigationViewControllerDidCancelFeedback(_ viewController: NavigationViewController)
  • Called when the user sends feedback.

    Declaration

    Swift

    @objc(navigationViewController:didSendFeedbackAssignedUUID:feedbackType:)
    optional func navigationViewController(_ viewController: NavigationViewController, didSendFeedbackAssigned uuid: UUID, feedbackType: FeedbackType)

    Parameters

    viewController

    The navigation view controller that reported the feedback.

    uuid

    The feedback event’s unique identifier.

    feedbackType

    The type of feedback event that was sent.

  • Returns the center point of the user course view in screen coordinates relative to the map view.

    Declaration

    Swift

    @objc
    optional func navigationViewController(_ navigationViewController: NavigationViewController, mapViewUserAnchorPoint mapView: NavigationMapView) -> CGPoint
  • Allows 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.isQualified property.

    Declaration

    Swift

    @objc(navigationViewController:shouldDiscardLocation:)
    optional func navigationViewController(_ navigationViewController: NavigationViewController, shouldDiscard location: CLLocation) -> Bool

    Parameters

    navigationViewController

    The navigation view controller that discarded the location.

    location

    The location that will be discarded.

    Return Value

    If true, the location is discarded and the NavigationViewController will not consider it. If false, the location will not be thrown out.

  • Called 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.

    Declaration

    Swift

    @objc(navigationViewController:roadNameAtLocation:)
    optional func navigationViewController(_ navigationViewController: NavigationViewController, roadNameAt location: CLLocation) -> String?

    Parameters

    navigationViewController

    The navigation view controller that will display the road name.

    location

    The user’s current location.

    Return Value

    The road name to display in the label, or nil to hide the label.