NavigationViewController

open class NavigationViewController : UIViewController, NavigationStatusPresenter, NavigationViewData, BuildingHighlighting
extension NavigationViewController: NavigationMapViewDelegate
extension NavigationViewController: NavigationServiceDelegate
extension NavigationViewController: StyleManagerDelegate
extension NavigationViewController: TopBannerViewControllerDelegate
extension NavigationViewController: BottomBannerViewControllerDelegate
extension NavigationViewController: CarPlayConnectionObserver

NavigationViewController is a fully-featured user interface for turn-by-turn navigation. Do not confuse it with the NavigationController class in UIKit.

You initialize a navigation view controller based on a predefined RouteResponse and NavigationOptions. As the user progresses along the route, the navigation view controller shows their surroundings and the route line on a map. Banners above and below the map display key information pertaining to the route. A list of steps and a feedback mechanism are accessible via the navigation view controller.

Route initialization should be configured before view controller’s view is loaded. Usually, that is automatically done during any of the inits, but you may also change this settings via prepareViewLoading(routeResponse:, routeIndex:, routeOptions:, navigationOptions:) methods. For example that could be handy while configuring a ViewController for a UIStoryboardSegue.

To be informed of significant events and decision points as the user progresses along the route, set the NavigationService.delegate property of the NavigationService that you provide when creating the navigation options.

CarPlayNavigationViewController manages the corresponding user interface on a CarPlay screen.

Important

Creating an instance of this type with parameters that uses RouteController with will start an Active Guidance session. The trip session is stopped when the instance is deallocated. For more info read the Pricing Guide.
  • A RouteResponse object constructed by MapboxDirections along with route index in it.

    In cases where you need to update the route after navigation has started, you can set a new route using Router.updateRoute(with:routeOptions:completion:) method in NavigationViewController.navigationService.router and NavigationViewController will update its UI accordingly.

    For example:

    • If you update route with the same waypoints as the current one: swift navigationViewController.navigationService.router.updateRoute(with: indexedRouteResponse, routeOptions: nil, completion: nil)
    • In case you update route with different set of waypoints: swift navigationViewController.navigationService.router.updateRoute(with: indexedRouteResponse, routeOptions: newRouteOptions, completion: nil)

    Declaration

    Swift

    public var indexedRouteResponse: IndexedRouteResponse { get }
  • A Route object constructed by MapboxDirections.

    Declaration

    Swift

    public var route: Route? { get }
  • Current RouteResponse object, as provided by MapboxDirections.

    Declaration

    Swift

    public var routeResponse: RouteResponse { get }
  • The index of the route within the original RouteResponse object.

    Declaration

    Swift

    public var routeIndex: Int? { get }
  • A reference to a MapboxDirections service. Used for rerouting.

    Declaration

    Swift

    @available(*, deprecated, message: "Use `navigationService.routingProvider` instead. If navigation service was not initialized using `Directions` object - this property is unused and ignored.")
    public var directions: Directions { get }
  • The navigation service that coordinates the view controller’s nonvisual components, tracking the user’s location as they proceed along the route.

    Declaration

    Swift

    private(set) public var navigationService: NavigationService! { get set }
  • Determines whether the user location annotation is moved from the raw user location reported by the device to the nearest location along the route.

    By default, this property is set to true, causing the user location annotation to be snapped to the route.

    Declaration

    Swift

    public var snapsUserLocationAnnotationToRoute: Bool
  • Toggles sending of UILocalNotification upon upcoming steps when application is in the background. Defaults to true.

    Declaration

    Swift

    public var sendsNotifications: Bool
  • The receiver’s delegate.

    Declaration

    Swift

    public weak var delegate: NavigationViewControllerDelegate?
  • If true, UIApplication.isIdleTimerDisabled is set to true in viewWillAppear(_:) and false in viewWillDisappear(_:). If your application manages the idle timer itself, set this property to false.

    Declaration

    Swift

    public var shouldManageApplicationIdleTimer: Bool { get set }
  • Initializes a NavigationViewController that presents the user interface for following a predefined route based on the given options.

    The route may come directly from the completion handler of the MapboxDirections framework’s Directions.calculate(_:completionHandler:) method, MapboxCoreNavigation MapboxRoutingProvider.calculateRoutes(options:completionHandler:), or it may be unarchived or created from a JSON object.

    Declaration

    Swift

    @available(*, deprecated, renamed: "init(for:navigationOptions:﹚")
    required public init(for routeResponse: RouteResponse, routeIndex: Int, routeOptions: RouteOptions, navigationOptions: NavigationOptions? = nil)

    Parameters

    routeResponse

    RouteResponse object, containing selection of routes to follow.

    routeIndex

    The index of the route within the original RouteResponse object.

    routeOptions

    The route options used to get the route.

    navigationOptions

    The navigation options to use for the navigation session.

  • Initializes a NavigationViewController that presents the user interface for following a predefined route based on the given options. The route may come directly from the completion handler of the MapboxDirections framework’s Directions.calculate(_:completionHandler:) method, MapboxCoreNavigation MapboxRoutingProvider.calculateRoutes(options:completionHandler:), or it may be unarchived or created from a JSON object.

    Declaration

    Swift

    required public init(for indexedRouteResponse: IndexedRouteResponse, navigationOptions: NavigationOptions? = nil)

    Parameters

    routeResponse

    IndexedRouteResponse object, containing selection of routes to follow.

    navigationOptions

    The navigation options to use for the navigation session.

  • Initializes a NavigationViewController that presents the user interface for following a predefined route based on the given options. The route may come directly from the completion handler of the MapboxDirections framework’s Directions.calculateRoutes(matching:completionHandler:) method, MapboxCoreNavigation MapboxRoutingProvider.calculateRoutes(options:completionHandler:), or it may be unarchived or created from a JSON object.

    Declaration

    Swift

    required public convenience init(for mapMatchingResponse: MapMatchingResponse, routeIndex: Int, navigationOptions: NavigationOptions? = nil) throws

    Parameters

    mapMatchingResponse

    MapMatchingResponse object, containing selection of routes to follow.

    routeIndex

    The index of the route within the original RouteResponse object.

    navigationOptions

    The navigation options to use for the navigation session.

  • Initializes a NavigationViewController with the given route and navigation service.

    Declaration

    Swift

    public convenience init(navigationService service: NavigationService)

    Parameters

    navigationService

    The navigation service that manages navigation along the route. Route data and options will be extracted from this instance.

  • Shows a Status for a specified amount of time.

    Declaration

    Swift

    public func show(_ status: StatusView.Status)
  • Hides a given Status without hiding the status view.

    Declaration

    Swift

    public func hide(_ status: StatusView.Status)
  • Updates key settings before loading the view.

    This method basically re-runs the setup which takes place in init. It could be useful if some of the attributes have changed before NavigationViewController did load it’s view, or if you did not have access to initializing logic. For example, as a part of UIStoryboardSegue configuration.

    Declaration

    Swift

    @available(*, deprecated, renamed: "prepareViewLoading(indexedRouteResponse:navigationOptions:﹚")
    public func prepareViewLoading(routeResponse: RouteResponse, routeIndex: Int, routeOptions: RouteOptions, navigationOptions: NavigationOptions? = nil) -> Bool

    Parameters

    routeResponse

    RouteResponse object, containing selection of routes to follow.

    routeIndex

    The index of the route within the original RouteResponse object.

    routeOptions

    The route options used to get the route.

    navigationOptions

    The navigation options to use for the navigation session.

  • Updates key settings before loading the view.

    This method basically re-runs the setup which takes place in init. It could be useful if some of the attributes have changed before NavigationViewController did load it’s view, or if you did not have access to initializing logic. For example, as a part of UIStoryboardSegue configuration.

    Declaration

    Swift

    public func prepareViewLoading(indexedRouteResponse: IndexedRouteResponse, navigationOptions: NavigationOptions? = nil) -> Bool

    Parameters

    indexedRouteResponse

    IndexedRouteResponse object, containing selection of routes to follow.

    navigationOptions

    The navigation options to use for the navigation session.