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.

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

    Default Implementation

    UnimplementedLogging prints a warning to standard output the first time this method is called.

    Declaration

    Swift

    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 movement of the user updates the route progress model.

    Default Implementation

    UnimplementedLogging prints 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

    navigationViewController

    The ViewController that received the new locations.

    progress

    the RouteProgress model that was updated.

    location

    the guaranteed location, possibly snapped, associated with the progress update.

    rawLocation

    the raw location, from the location manager, associated with the progress update.

  • Tells the receiver that the final destination PointAnnotation was added to the NavigationViewController.

    Default Implementation

    UnimplementedLogging prints a warning to standard output the first time this method is called.

    Declaration

    Swift

    func navigationViewController(_ navigationViewController: NavigationViewController, didAdd finalDestinationAnnotation: PointAnnotation, pointAnnotationManager: PointAnnotationManager)

    Parameters

    navigationViewController
    finalDestinationAnnotation

    The point annotation that was added to the map view.

    pointAnnotationManager

    The object that manages the point annotation in the map view.

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

    UnimplementedLogging prints 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

    navigationViewController

    The Navigation VC that is detecting the users’ approach.

    waypoint

    The waypoint that the service is arriving at.

    remainingTimeInterval

    The estimated number of seconds until arrival.

    distance

    The current distance from the waypoint, in meters.

  • 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 using the Router.advanceLegIndex(completionHandler:) method. Obtain Router via the NavigationViewController.navigationService and NavigationService.router properties.

    Default Implementation

    UnimplementedLogging prints a warning to standard output the first time this method is called.

    Declaration

    Swift

    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 an LineLayer that 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

    UnimplementedLogging prints 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

    navigationViewController

    The NavigationViewController object, on surface of which route line is drawn.

    identifier

    The LineLayer identifier.

    sourceIdentifier

    Identifier of the source, which contains the route data that this method would style.

    Return Value

    A LineLayer that is applied to the route line.

  • Returns an LineLayer that 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

    UnimplementedLogging prints 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

    navigationViewController

    The NavigationViewController object, on surface of which route line is drawn.

    identifier

    The LineLayer identifier.

    sourceIdentifier

    Identifier of the source, which contains the route data that this method would style.

    Return Value

    A LineLayer that is applied as a casing around the route line.

  • Returns an LineLayer that 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

    UnimplementedLogging prints 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

    navigationViewController

    The NavigationViewController object, on surface of which route line is drawn.

    identifier

    The LineLayer identifier.

    sourceIdentifier

    Identifier of the source, which contains the route data that this method would style.

    Return Value

    A LineLayer that is applied as restricted areas on the route line.

  • Returns an CircleLayer that 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 by navigationViewController(_:waypointSymbolLayerWithIdentifier:sourceIdentifier:).

    If this method is unimplemented, the navigation view controller’s map view marks each destination waypoint with a circle.

    Default Implementation

    UnimplementedLogging prints 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

    navigationViewController
    identifier

    The CircleLayer identifier.

    sourceIdentifier

    Identifier of the source, which contains the waypoint data that this method would style.

    Return Value

    A CircleLayer that the map applies to all waypoints.

  • Returns a SymbolLayer that 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 by navigationViewController(_: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

    UnimplementedLogging prints 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

    navigationViewController
    identifier

    The SymbolLayer identifier.

    sourceIdentifier

    Identifier of the source, which contains the waypoint data that this method would style.

    Return Value

    A SymbolLayer that the map applies to all waypoint symbols.

  • Returns a FeatureCollection that 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

    UnimplementedLogging prints 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

    navigationViewController
    waypoints

    The waypoints to be displayed on the map.

    legIndex

    Index, which determines for which RouteLeg Waypoint will be shown.

    Return Value

    Optionally, a FeatureCollection that defines the shape of the waypoint, or nil to use default behavior.

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

    Default Implementation

    UnimplementedLogging prints a warning to standard output the first time this method is called.

    Declaration

    Swift

    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.

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

    Default Implementation

    UnimplementedLogging prints a warning to standard output the first time this method is called.

    Declaration

    Swift

    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.

  • UnimplementedLogging prints a warning to standard output the first time this method is called.

    Declaration

    Swift

    func navigationViewController(_ navigationViewController: NavigationViewController, didSelect route: Route)