Navigation SDK for iOS

Current version: v0.38.0 View changelog

  • A navigation UI ready to drop into your application
  • Professionally designed map styles
  • Worldwide driving, cycling, and walking directions
  • Traffic avoidance and proactive rerouting

The Mapbox Navigation SDK gives you all the tools you need to add turn-by-turn navigation to your application. It takes only a few minutes to drop a full-fledged turn-by-turn navigation view controller into your application. Or use the Core Navigation framework directly to build something truly custom.

Structure of the SDK

The Navigation SDK is divided into two frameworks: the Mapbox Core Navigation framework (MapboxCoreNavigation) and the Mapbox Navigation framework (MapboxNavigation).

Mapbox Core Navigation

The Mapbox Core Navigation framework (MapboxCoreNavigation) contains the logic that allows you to receive user location updates, determine their relation to the route line, and get notifications that indicate the current state of the application in the form of a RouteProgress object.

You can use MapboxCoreNavigation directly in your project to build a completely custom navigation UI or use it via the Mapbox Navigation framework (MapboxNavigation), which is powered by MapboxCoreNavigation.

Mapbox Navigation

The Mapbox Navigation framework (MapboxNavigation) is the ready-made turn-by-turn navigation user interface (UI). Use MapboxNavigation to get up and running quickly with an in-app navigation experience. With a few lines of code, add a drop-in UI, automatic day-to-night map switching, and automatic rerouting in traffic. Adjust the style of various elements of the ready-made UI, react to location-related events as they occur, and adjust various aspects of the map view’s appearance.

Requirements

The Mapbox Navigation SDK and Core Navigation are compatible with applications written in Swift 4.2 or Objective-C in Xcode 10.0. The Mapbox Navigation and Mapbox Core Navigation frameworks run on iOS 9.0 and above.

Product capabilities

This documentation contains information for both the Mapbox Core Navigation and Mapbox Navigation libraries across a variety of topics:

Build route requests

Track progress along a route

Other topics

Installation

You can install the Mapbox Navigation SDK for iOS using either CocoaPods or Carthage. Completing either of these two installation options will provide access to the Mapbox Navigation SDK, map services, and directions services.

Installing MapboxNavigation versus MapboxCoreNavigation

MapboxCoreNavigation is a dependency of MapboxNavigation. If you install MapboxNavigation you will also have access to all MapboxCoreNavigation's classes and methods. If you do not plan to use the drop-in UI, you can replace MapboxNavigation with MapboxCoreNavigation in the Podfile code snippet below.

CocoaPods

To install Mapbox Navigation using CocoaPods:

  1. Create a Podfile with the following specification:

    pod 'MapboxNavigation', '~> 0.38.0'
    
  2. Run pod repo update && pod install and open the resulting Xcode workspace.

Carthage

Alternatively, to install Mapbox Navigation using Carthage:

  1. Create a Cartfile with the following dependency:

    github "mapbox/mapbox-navigation-ios" ~> 0.38.0
    
  2. Run carthage update --platform iOS to build only the iOS dependencies.

  3. Follow the rest of Carthage’s iOS integration instructions. Your application target’s Embedded Frameworks should include MapboxNavigation.framework, MapboxCoreNavigation.framework, and MapboxNavigationNative.framework.

Configuration

  1. Mapbox APIs and map tiles require a Mapbox account and API access token. In the project editor, select the application target, then go to the Info tab. Under the “Custom iOS Target Properties” section, set MGLMapboxAccessToken to your access token. You can get an access token from the Mapbox account page.

  2. In order for the SDK to track the user’s location as they move along the route, set NSLocationWhenInUseUsageDescription to:

    Shows your location on the map and helps improve the map.

  3. Users expect the SDK to continue to track the user’s location and deliver audible instructions even while a different application is visible or the device is locked. To do this, go to the Capabilities tab. Under the Background Modes section, enable “Audio, AirPlay, and Picture in Picture” and “Location updates”. (Alternatively, add the audio and location values to the UIBackgroundModes array in the Info tab.)

Now import the relevant modules and present a new NavigationViewController. You can also push to a navigation view controller from within a storyboard if you set up your application’s UI in Interface Builder.

import MapboxDirections
import MapboxCoreNavigation
import MapboxNavigation
// Define two waypoints to travel between
let origin = Waypoint(coordinate: CLLocationCoordinate2D(latitude: 38.9131752, longitude: -77.0324047), name: "Mapbox")
let destination = Waypoint(coordinate: CLLocationCoordinate2D(latitude: 38.8977, longitude: -77.0365), name: "White House")

// Set options
let options = NavigationRouteOptions(waypoints: [origin, destination])

// Request a route using MapboxDirections.swift
Directions.shared.calculate(options) { (waypoints, routes, error) in
    guard let route = routes?.first else { return }
    // Pass the generated route to the the NavigationViewController
    let viewController = NavigationViewController(for: route)
    viewController.modalPresentationStyle = .fullScreen
    present(viewController, animated: true, completion: nil)
}

Testing and development

Simulate a route

Use MapboxNavigationService(simulating:.always) to simulate progress along a route. This simulation mode is different from the simulation features built into both the Simulator and Xcode. The simulation mode built into the Navigation SDK never deviates from the current route, but it does behave more realistically by accounting for the expected travel speed and course at any given time. While navigating, you can double-tap the left or right side of the “Simulating” banner to adjust the playback speed.

let navigationService = MapboxNavigationService(route: route, simulating: .always)
let navigationOptions = NavigationOptions(navigationService: navigationService)
let viewController = NavigationViewController(for: route, options: navigationOptions)

Pricing

See our pricing page for more details.

Available resources

For further details, consult the guides and examples included with this API reference. Documentation for the Mapbox Navigation SDK for iOS comes in the form of:

We welcome your bug reports, feature requests, and contributions. If you can't find what you're looking for, reach out to our support team.

Was this page helpful?