All docsMaps SDK for iOSExamplesAdd a marker to the map

Add a marker to the map

Use MapView's AnnotationOrchestrator class to create a PointAnnotationManager. Create instances of PointAnnotation and add them to the PointAnnotationManager using the var annotations: [PointAnnotation] property.

This example requires an additional asset. Click the button below to download the asset, then add it to your Xcode project's asset catalog and specify it by name as the point annotation's image.

Download ZIP

There are several ways to add markers, annotations, and other shapes to the map using the Maps SDK. To choose the best approach for your application, read the Markers and annotations guide.

import UIKit
import MapboxMaps
class ViewController: UIViewController {
var mapView: MapView!
override func viewDidLoad() {
// Center the map camera over Copenhagen.
let centerCoordinate = CLLocationCoordinate2D(latitude: 55.665957, longitude: 12.550343)
let options = MapInitOptions(cameraOptions: CameraOptions(center: centerCoordinate, zoom: 8.0))
mapView = MapView(frame: view.bounds, mapInitOptions: options)
mapView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
// We want to display the annotation at the center of the map's current viewport
let centerCoordinate =
// Make a `PointAnnotationManager` which will be responsible for managing a
// collection of `PointAnnotation`s.
let pointAnnotationManager = mapView.annotations.makePointAnnotationManager()
// Initialize a point annotation with a single coordinate
// and configure it with a custom image (sourced from the asset catalogue)
var customPointAnnotation = PointAnnotation(coordinate: centerCoordinate)
// Make the annotation show a red pin
customPointAnnotation.image = .init(image: UIImage(named: "red_pin")!, name: "red_pin")
// Add the annotation to the manager in order to render it on the map.
pointAnnotationManager.annotations = [customPointAnnotation]