Skip to main content

Add circle annotations

Show circle annotations on a map.

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

final class ViewController: UIViewController {
private lazy var mapView: MapView = MapView(frame: view.bounds)

override func viewDidLoad() {

let cameraOptions = CameraOptions(center: CLLocationCoordinate2D(latitude: 0, longitude: 0), zoom: 2)
let mapInitOptions = MapInitOptions(cameraOptions: cameraOptions)
mapView = MapView(frame: view.bounds, mapInitOptions: mapInitOptions)
mapView.autoresizingMask = [.flexibleWidth, .flexibleHeight]

// Create the CircleAnnotationManager
// Annotation managers are kept alive by `AnnotationOrchestrator`
// (`mapView.annotations`) until you explicitly destroy them
// by calling `mapView.annotations.removeAnnotationManager(withId:)`
let circleAnnotationManager = mapView.annotations.makeCircleAnnotationManager()

var annotations = [CircleAnnotation]()
for _ in 0...2000 {
var annotation = CircleAnnotation(centerCoordinate: .random)
annotation.circleColor = StyleColor(.random)
annotation.circleRadius = 12
annotation.isDraggable = true
annotation.tapHandler = { [id =] _ in
print("tapped annotation \(id)")
return false

circleAnnotationManager.annotations = annotations

Was this example helpful?