NavigationViewController
open class NavigationViewController : UIViewController, NavigationStatusPresenter, NavigationViewData
extension NavigationViewController: NavigationServiceDelegate
extension NavigationViewController: StyleManagerDelegate
extension NavigationViewController: TopBannerViewControllerDelegate
extension NavigationViewController: BottomBannerViewControllerDelegate
extension NavigationViewController: CarPlayConnectionObserver
extension NavigationViewController: NavigationMapViewDelegate
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 init
s, 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 usesRouteController
with will start an Active
Guidance session. The trip session is stopped when the instance is deallocated. For more info read the
Pricing Guide.
-
The
NavigationMapView
displayed inside the view controller.Note
Do not changeNavigationMapView.delegate
property; instead, implement the corresponding methods onNavigationViewControllerDelegate
.Declaration
Swift
@objc public var navigationMapView: NavigationMapView? { get }
-
Controls whether the main route style layer and its casing disappears as the user location puck travels over it. Defaults to
false
.If
true
, the part of the route that has been traversed will be rendered with full transparency, to give the illusion of a disappearing route. To customize the color that appears on the traversed section of a route, override thetraversedRouteColor
property for theNavigationMapView.appearance()
.Declaration
Swift
public var routeLineTracksTraversal: Bool { get set }
-
The voice controller that vocalizes spoken instructions along the route at the appropriate times.
Declaration
Swift
public var voiceController: RouteVoiceController!
-
A Boolean value that determines whether the map annotates the locations at which instructions are spoken for debugging purposes.
Defaults to
false
.Declaration
Swift
public var annotatesSpokenInstructions: Bool { get set }
-
The
NavigationOptions
object, which is used for the navigation session.Declaration
Swift
public var navigationOptions: NavigationOptions?
-
The route options used to get the route.
Declaration
Swift
public var routeOptions: RouteOptions? { get }
-
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 inNavigationViewController.navigationService.router
andNavigationViewController
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 }
- If you update route with the same waypoints as the current one:
-
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 }
-
An instance of
Directions
need for rerouting. See Mapbox Directions for further information.Declaration
Swift
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 totrue
inviewWillAppear(_:)
andfalse
inviewWillDisappear(_:)
. If your application manages the idle timer itself, set this property tofalse
.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, or it may be unarchived or created from a JSON object.Declaration
Swift
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
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 beforeNavigationViewController
did load it’s view, or if you did not have access to initializing logic. For example, as a part ofUIStoryboardSegue
configuration.Declaration
Swift
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.
-
Shows a button that allows drivers to report feedback such as accidents, closed roads, poor instructions, etc. Defaults to
true
.Declaration
Swift
public var showsReportFeedback: Bool { get set }
-
Shows End of route Feedback UI when the route controller arrives at the final destination.
Defaults to
true.
Declaration
Swift
public var showsEndOfRouteFeedback: Bool { get set }
-
Shows the current speed limit on the map view.
The default value of this property is
true
.Declaration
Swift
public var showsSpeedLimits: Bool { get set }
-
Controls whether or not the FeedbackViewController shows a second level of detail for feedback items.
Defaults to
false
.Declaration
Swift
public var detailedFeedbackEnabled: Bool { get set }
-
The position of floating buttons in a navigation view. The default value is
MapOrnamentPosition.topTrailing
.Declaration
Swift
open var floatingButtonsPosition: MapOrnamentPosition? { get set }
-
The floating buttons in an array of UIButton in navigation view. The default floating buttons include the overview, mute and feedback report button. The default type of the floatingButtons is
FloatingButton
, which is declared withFloatingButton.rounded(image:selectedImage:size:)
to be consistent.Declaration
Swift
open var floatingButtons: [UIButton]? { get set }
-
If true, the map style and UI will automatically be updated given the time of day.
Declaration
Swift
public var automaticallyAdjustsStyleForTimeOfDay: Bool { get set }
-
Allows to control highlighting of the destination building on arrival. By default destination buildings will not be highlighted.
Declaration
Swift
public var waypointStyle: WaypointStyle
-
Controls the styling of NavigationViewController and its components.
The style can be modified programmatically by using
StyleManager.applyStyle(type:)
.Declaration
Swift
public private(set) var styleManager: StyleManager! { get }
-
Declaration
Swift
public func navigationService(_ service: NavigationService, shouldRerouteFrom location: CLLocation) -> Bool
-
Declaration
Swift
public func navigationService(_ service: NavigationService, willRerouteFrom location: CLLocation)
-
Declaration
Swift
public func navigationService(_ service: NavigationService, didRerouteAlong route: Route, at location: CLLocation?, proactive: Bool)
-
Declaration
Swift
public func navigationService(_ service: NavigationService, didFailToRerouteWith error: Error)
-
Declaration
Swift
public func navigationService(_ service: NavigationService, didRefresh routeProgress: RouteProgress)
-
Declaration
Swift
public func navigationService(_ service: NavigationService, shouldDiscard location: CLLocation) -> Bool
-
Declaration
Swift
public func navigationService(_ service: NavigationService, didUpdate progress: RouteProgress, with location: CLLocation, rawLocation: CLLocation)
-
Declaration
Swift
public func navigationService(_ service: NavigationService, didPassSpokenInstructionPoint instruction: SpokenInstruction, routeProgress: RouteProgress)
-
Declaration
Swift
public func navigationService(_ service: NavigationService, didPassVisualInstructionPoint instruction: VisualInstructionBanner, routeProgress: RouteProgress)
-
Declaration
Swift
public func navigationService(_ service: NavigationService, willArriveAt waypoint: Waypoint, after remainingTimeInterval: TimeInterval, distance: CLLocationDistance)
-
Declaration
Swift
public func navigationService(_ service: NavigationService, didArriveAt waypoint: Waypoint) -> Bool
-
Declaration
Swift
public func navigationService(_ service: NavigationService, willBeginSimulating progress: RouteProgress, becauseOf reason: SimulationIntent)
-
Declaration
Swift
public func navigationService(_ service: NavigationService, didBeginSimulating progress: RouteProgress, becauseOf reason: SimulationIntent)
-
Declaration
Swift
public func navigationService(_ service: NavigationService, willEndSimulating progress: RouteProgress, becauseOf reason: SimulationIntent)
-
Declaration
Swift
public func navigationService(_ service: NavigationService, didEndSimulating progress: RouteProgress, becauseOf reason: SimulationIntent)
-
Declaration
Swift
public func navigationService(_ service: NavigationService, shouldPreventReroutesWhenArrivingAt waypoint: Waypoint) -> Bool
-
Declaration
Swift
public func navigationServiceShouldDisableBatteryMonitoring(_ service: NavigationService) -> Bool
-
Declaration
Swift
public func navigationServiceDidChangeAuthorization(_ service: NavigationService, didChangeAuthorizationFor locationManager: CLLocationManager)
-
Declaration
Swift
public func location(for styleManager: StyleManager) -> CLLocation?
-
Declaration
Swift
public func styleManager(_ styleManager: StyleManager, didApply style: Style)
-
Declaration
Swift
public func styleManagerDidRefreshAppearance(_ styleManager: StyleManager)
-
Declaration
Swift
public func didTapCancel(_ sender: Any)
-
Declaration
Swift
public func didConnectToCarPlay()
-
Declaration
Swift
public func didDisconnectFromCarPlay()
-
Declaration
Swift
public func navigationMapView(_ navigationMapView: NavigationMapView, routeLineLayerWithIdentifier identifier: String, sourceIdentifier: String) -> LineLayer?
-
Declaration
Swift
public func navigationMapView(_ navigationMapView: NavigationMapView, routeCasingLineLayerWithIdentifier identifier: String, sourceIdentifier: String) -> LineLayer?
-
Declaration
Swift
public func navigationMapView(_ navigationMapView: NavigationMapView, waypointCircleLayerWithIdentifier identifier: String, sourceIdentifier: String) -> CircleLayer?
-
Declaration
Swift
public func navigationMapView(_ navigationMapView: NavigationMapView, waypointSymbolLayerWithIdentifier identifier: String, sourceIdentifier: String) -> SymbolLayer?
-
Declaration
Swift
public func navigationMapView(_ navigationMapView: NavigationMapView, shapeFor waypoints: [Waypoint], legIndex: Int) -> FeatureCollection?
-
Declaration
Swift
public func navigationMapView(_ navigationMapView: NavigationMapView, didAdd finalDestinationAnnotation: PointAnnotation, pointAnnotationManager: PointAnnotationManager)