Mapbox iOS SDK
Start building
The Mapbox iOS SDK requires Xcode 8 or above. You will need to update your version of Xcode if you are using Xcode 7.x or below.
Access tokens
An access token is necessary to use Mapbox services and APIs, such as maps, directions, and telemetry. Your access tokens can be managed in your account settings, where you can retrieve current tokens and generate new ones. You should create a new token for each of your apps, which will help you track usage and minimize disruption in the event a token needs to be revoked.
There are two ways to provide an access token in your app:
- In the
Info.plistfile (in the Project Navigator, or in the Info tab of the project editor), setMGLMapboxAccessToken. - In the app delegate method
application:didFinishLaunchingWithOptions:, use-[MGLAccountManager setAccessToken:].
Telemetry opt out
Mapbox Telemetry is a powerful location analytics platform included in this SDK. By default, anonymized location and usage data is sent to Mapbox whenever the host app causes it to be gathered. The Mapbox Terms of Service require your app to provide users with a way to individually opt out of Mapbox Telemetry, which is provided automatically as part of the attribution control.
If you hide the attribution control, you must provide an alternative opt out in one of two ways:
- Add a setting to your application’s section in the system Settings app using a
Settings.bundlein your application bundle. An exampleSettings.bundleis included with the SDK. If you installed the SDK via CocoaPods or Carthage, download the example bundle (source code). - Integrate the setting directly into your app. Hook a
UISwitchcontrol up to theMGLMapboxMetricsEnabledBoolean user default, which should beYESby default. Then setMGLMapboxMetricsEnabledSettingShownInApptoYESin your app’sInfo.plistfile.
Location services
In order to show the user’s position on the map, you must first ask for their permission. In iOS 8 and above, this is accomplished by creating and setting the NSLocationAlwaysUsageDescription and/or NSLocationWhenInUseUsageDescription keys in the Info.plist file.
Enabling MGLMapView.showsUserLocation will automatically ask for the necessary permission and, once granted, will place an annotation on the map at the user’s location.
In most cases, you will only need to provide one usage description key. If both location usage description keys are defined and permission has not yet been granted by the user, this SDK will request "when in use" authorization. For more information on these keys and iOS location permissions in general, see NSHipster's comprehensive overview.
API introduction
Below are some of the major components used when building a map-based iOS app with Mapbox:
- Map view (
MGLMapViewclass) - The map view is an interactive world map that pans and zooms in response to gestures. Optionally, use the correspondingMGLMapViewDelegateprotocol to customize annotations, respond to user interaction, and more.MGLMapViewDelegatefollows Cocoa's delegation design pattern. - Annotations (
MGLAnnotationprotocol) - Use an annotation to present data points and custom points of interest atop the map view. The premadeMGLPointAnnotationclass makes it easy to add a basic, pin-like point annotation. Alternatively, have your own model class adopt theMGLAnnotationprotocol to have the map view serve as a container for your data. Use theMGLAnnotationViewclass for further visual customization and tight integration with UIKit. - Style (
MGLStyleclass) -MGLStyleprovides access to the runtime styling API, with options for controlling every aspect of the map’s content and appearance in real time. The runtime styling API offers a more powerful alternative to annotations for data visualizations. - Offline maps (
MGLOfflineStorageclass) - An offline pack makes a region of the map available even when a network connection is unavailable or unreliable. Use the singletonMGLOfflineStorageobject to download and manageMGLOfflinePacks.
Full API documentation is available on the web, in the binary download package, or right in Xcode, either inline or in Xcode’s Quick Help inspector.

Map styles
All Mapbox accounts have access to our professionally-designed template styles. You can also design your own custom styles visually within Mapbox Studio for use with the Mapbox iOS SDK. See our examples for using one of our template styles or a custom style designed in Mapbox Studio.
Attribution
If your application displays a map using Mapbox map designs or data, you must display the Mapbox wordmark and text attribution. The Mapbox iOS SDK will add attribution to your maps automatically. For more information about required attribution, see our guidelines.
Additional Mapbox libraries
In addition to the Mapbox iOS SDK, we also provide libraries that connect to other Mapbox services using a familiar, object-oriented interface.
Navigation
The Mapbox Navigation SDK for iOS gives you all the tools you need to add turn-by-turn navigation to your application, powered by MapboxDirections.swift. It works with both Swift and Objective-C on iOS to provide drop-in UI components for navigation while supporting routing profiles for driving, walking, and cycling directions. It also includes features such as maneuver announcements, traffic avoidance, and automatic rerouting. With the Mapbox Navigation SDK for iOS, you can integrate navigation within your own application without having to send your users to a third party navigation service.
Download the Mapbox Navigation SDK for iOS from GitHub or install it with CocoaPods or Carthage.
Directions
MapboxDirections.swift connects your application to the Mapbox Directions API. It is compatible with both Objective-C and Swift on iOS, macOS, tvOS, and watchOS. Quickly get driving, cycling, or walking directions, whether the trip is nonstop or it has multiple stopping points, all using a simple interface reminiscent of MapKit’s MKDirections.
Geocoder
MapboxGeocoder.swift connects your application to the Mapbox Geocoding API. It works with both Swift and Objective-C on iOS, macOS, tvOS, and watchOS. Easily convert an address or place name into a coordinate pair or vice versa, all using a simple interface similar to the Core Location framework’s CLGeocoder. MapboxGeocoder.swift integrates with both Core Location and the Contacts framework.
Download MapboxGeocoder.swift from GitHub or install it with CocoaPods or Carthage.
Static maps
MapboxStatic.swift connects your application to the Mapbox Static API. It works with both Swift and Objective-C on iOS, macOS, tvOS, and watchOS. Quickly generate a static map image with markers and other overlays. Static maps are best suited for table views and other space- or memory-constrained environments in which the map doesn’t need to respond to gestures. If the map still needs to work when the device is offline, consider using the Mapbox iOS SDK’s offline map feature instead.
Download MapboxStatic.swift from GitHub or install it with CocoaPods or Carthage.
Need help?
Our Help page is filled with how-to references and guides so you can master our tools.
Carthage