Mapbox provides a robust Examples app to show various best practices and techniques for building with the Maps SDK for iOS. This tutorial shows the steps necessary to get the demo app running on an iOS emulator via Xcode in your development environment.
To start building your own app using the Maps SDK, see our Get Started with the Maps SDK for iOS guide.
If you haven't done so already, sign up for a Mapbox account and or log in to your existing account.
Create a new file .mapbox
in your user directory (~/.mapbox
) containing a public access token. You can use your default public token for this value.
pk.12345...
mapbox-maps-ios
repository with meThe examples app lives in a the Apps/Examples
directory of the Maps SDK for iOS code, available on GitHub. Use git to clone the repository on your development machine.
$git clone git@github.com:mapbox/mapbox-maps-ios.git
Examples.xcodeproj
.Now you should see the Examples project successfully loaded in the Project Navigator pane.
Be sure you have an iOS emulator selected, then click the Run button. Xcode will build and run the Maps SDK for iOS examples app on your emulator.
You will see a listing with the title and description for each example, grouped by category. Tap each example to explore and learn the capabilities of the Mapbox Maps SDK for iOS, including user location, markers and annotations, camera control and animation, and offline use.
If the app loads but you see a black background where the map should be, this means that the public access token was not properly configured and network requests for Mapbox resources are failing.
A build script reads your public access token from ~/.mapbox
and sets the value MBXAccessToken
in the example app's Info.plist
file.
Try inspecting the Info.plist
to confirm that MBXAccessToken
exists and contains the correct public access token value, then run the app again.
Each example lives in its own swift file, and you can explore the source code as you preview the examples in the emulator to learn how each example works. You may also want to change values and hot reload the app to change the functionality.
A good first customization might be to update the initial camera settings in BasicMapExample.swift
, the source code for the Display a map view example. See if you can make the map initialize on a different location by updating the center
coordinates in CameraOptions
. You can also experiment with different values for zoom
, bearing
, and pitch
,
With the Examples app running locally, you're ready to start exploring all the possibilities of the Maps SDK for iOS as you build maps into your iOS apps. Be sure to explore the SDK's documentation to level up, and share questions and lessons learned in the Mapbox Developer Discord.
This guide walks you through integrating the Maps SDK for iOS into your application, configuring your credentials, and adding a map to your app.
This example shows you how to add a marker to a Point of Interest (POI), using a point annotation
.
This guide shows you how to access the user's location from your app.