To install the Mapbox iOS SDK within your own application, check out the installation page to get started. Once installed, you can start building by exploring the SDK documentation, examples, and tutorials.
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.
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), set
- In the app delegate method
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 example
Settings.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 the
MGLMapboxMetricsEnabledBoolean user default, which should be
YESby default. Then set
YESin your app’s
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
NSLocationWhenInUseUsageDescription keys in the
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.
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 corresponding
MGLMapViewDelegateprotocol to customize annotations, respond to user interaction, and more.
MGLMapViewDelegatefollows Cocoa’s delegation design pattern.
- Annotations ([
MLAnnotation] class) - Use an annotation to present data points and custom points of interest atop the map view. The premade
MGLPointAnnotationclass makes it easy to add a basic, pin-like point annotation. Alternatively, have your own model class adopt the
MGLAnnotationprotocol to have the map view serve as a container for your data. Use the
MGLAnnotationViewclass for further visual customization and tight integration with UIKit.
- Style (
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 singleton
MGLOfflineStorageobject to download and manage
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.
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.
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.
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
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.
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.