Mapbox Navigation gives you all the tools you need to add turn-by-turn navigation to your apps.
Get up and running in a few minutes with our drop-in turn-by-turn navigation RouteViewController
, or build a completely custom turn-by-turn navigation app with our core components for routing and navigation.
- Drop-in turn-by-turn navigation UI
- Automotive, cycling, and walking directions
- Traffic avoidance
- Maneuver announcements
- Text instructions
- Text to speech support via AVSpeechSynthesizer or Amazon Polly
- Automatic rerouting
- Snap to route
To install Mapbox Navigation using Carthage v0.19.0 or above:
-
Specify the following dependency in your Cartfile:
github "mapbox/mapbox-navigation-ios" ~> 0.3.0
-
Run
carthage update --platform iOS
to build just the iOS dependencies. -
Follow the rest of Carthage’s iOS integration instructions. Your application target’s Embedded Frameworks should include MapboxNavigation.framework and MapboxCoreNavigation.framework.
Alternatively, to install Mapbox Navigation using CocoaPods:
- Specify the following dependency in your Podfile:
pod 'MapboxNavigation', '~> 0.3.0'
- Run
pod install
and open the resulting Xcode workspace.
Note, you may need to run pod repo update
before pod install
if your Cocoapods sources haven't been updated in a while.
- Clone the repository or download the .zip file
- Run
carthage update --platform ios
to build just the iOS dependencies - Open
MapboxNavigation.xcodeproj
- Sign up or log in to your Mapbox account and grab a Mapbox Access Token
- Open the
Info.plist
for eitherExample-Swift
orExample-Objective-C
and paste your Mapbox Access Token intoMGLMapboxAccessToken
- Build and run the
Example-Swift
orExample-Objective-C
target
import MapboxDirections
import MapboxNavigation
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")
let options = RouteOptions(waypoints: [origin, destination], profileIdentifier: .automobileAvoidingTraffic)
options.routeShapeResolution = .full
options.includesSteps = true
Directions.shared.calculate(options) { (waypoints, routes, error) in
guard let route = routes?.first else { return }
let viewController = NavigationViewController(for: route)
self.present(viewController, animated: true, completion: nil)
}
Mapbox Navigation requires a few additions to your Info.plist
. Be sure to sign up or log in to your Mapbox account and grab a Mapbox Access Token.
- Add a
MGLMapboxAccessToken
key and paste your Mapbox Access Token - Add a
NSLocationWhenInUseUsageDescription
key if you haven't already - If you need voice guidance while your app is in the background, you'll also need to add the
audio
andlocation
value to theUIBackgroundModes
array. You can also do this by navigating to theCapabilities
tab ->Background Modes
and enabling the following:Audio, AirPlay, and Picture in Picture
Location updates
See this guide for usage with storyboards.
You can customize the appearance in order to blend in with the rest of your app.
let style = Style()
style.maneuverViewHeight = 80
style.primaryTextColor = .black
style.headerBackgroundColor = .white
style.cellTitleLabelFont = .preferredFont(forTextStyle: .headline)
style.apply()
Or for a specific system trait in an interface’s environment. For instance only when being used on an iPad.
let style = Style(traitCollection: UITraitCollection(userInterfaceIdiom: .pad))
style.cellTitleLabelFont = .preferredFont(forTextStyle: .title1)
style.apply()
routeControllerDidCancelNavigation
: Fired when the user tapsCancel
. You are responsible for dismissing the UI
Mapbox Navigation gives you all the components you need, should you want to build your own custom turn-by-turn navigation UI:
- Mapbox Maps SDK
- Mapbox Studio
- Design custom maps with live traffic overlays
- MapboxDirections
- Automotive, cycling, and walking directions
- Traffic-influenced driving directions
- Mapbox Core Navigation (
MapboxCoreNavigation
module)- Route controller
- Progress calculations
- Location snapping
- Guidance notifications
- Current progress along a route
- Departure and arrival notifications
- Upcoming maneuver notifications
- Rerouting notifications
- Geometry functions
- Distance formatter
- Route controller
To install Mapbox Core Navigation using Carthage v0.19.0 or above:
-
Specify the following dependency in your Cartfile:
github "mapbox/mapbox-navigation-ios" ~> 0.3.0
-
Run
carthage update --platform iOS
to build just the iOS dependencies. -
Follow the rest of Carthage’s iOS integration instructions. Your application target’s Embedded Frameworks should include MapboxCoreNavigation.framework.
Alternatively, to install Mapbox Core Navigation using CocoaPods:
-
Specify the following dependency in your Podfile:
pod 'MapboxCoreNavigation', '~> 0.3.0'
-
Run
pod install
and open the resulting Xcode workspace.
RouteController
is given a route. Internally RouteController
matches the user's current location to the route while looking at 3 principle pieces:
- Is the user on or off the route?
- How far along the step is the user?
- Does the user need to be alerted about an upcoming maneuver?
The library compares the user from the route and decides upon each one of these parameters and acts accordingly. The developer is told what is happening behind the scenes via NSNotification
.
This library relies heavily on NSNotification
s for letting the developer know when events have occurred.
- Emitted when the user moves along the route. Notification contains 3 keys:
RouteControllerProgressDidChangeNotificationProgressKey
-RouteProgress
- Current progress along routeRouteControllerProgressDidChangeNotificationLocationKey
-CLLocation
- Current locationRouteControllerProgressDidChangeNotificationSecondsRemainingOnStepKey
-Double
- Given users speed and location, this is the number of seconds left to the end of the step
- Emitted when the alert level changes. This indicates the user should be notified about the upcoming maneuver. See [Alerts](#Alert levels). Notification contains 3 keys:
RouteControllerProgressDidChangeNotificationProgressKey
-RouteProgress
- Current progress along routeRouteControllerAlertLevelDidChangeNotificationDistanceToEndOfManeuverKey
-CLLocationDistance
- The users snapped distance to the end of the route.
- Emitted when the user is off the route and should be rerouted. Notification contains 1 key:
RouteControllerNotificationShouldRerouteKey
-CLLocation
- Last location of user
Alert levels indicate the type of announcement that should be given. The enum types available are:
none
depart
- Emitted while departing originlow
- Emitted directly after completing the maneuvermedium
- Emitted when the user has 70 seconds remaining on the route.high
- Emitted when the user has 15 seconds remaining on the route.arrive
- Emitted when the user arrives at destination
In the event of a reroute, it's necessary to update the current route with a new route. Once fetched, you can update the current route by:
navigation.routeProgress = RouteProgress(route: newRoute)
Mapbox Navigation SDK for iOS is released under the ISC License. See LICENSE for details.