Map annotations in SwiftUI and MapKit

Platform & distribution Junior Swift 5.9+ iOS 17+ Reviewed By Alok Singh

Fill the blank

Fill the blank to show a standard balloon marker with each store's name.

Map {
    ForEach(stores) { store in
        ____(store.name, coordinate: store.coordinate)
    }
}
Options
Hint 1 of 1

The standard balloon has its own type.

Choose an answer, then open Show answer below to check it.

Show answer

Answer: A Marker

Correct. It draws the system balloon with a title.

Why not the others?
  • B MapPin. MapPin is deprecated in iOS 17 and isn't used in MapContent builders.
  • C MKPointAnnotation. That's a UIKit/MapKit class, not SwiftUI map content.
  • D Annotation. Annotation also takes a custom view closure; Marker is the standard balloon.

30-second answer

In SwiftUI (iOS 17+), build map content inside Map { }: Marker for the standard balloon with a title or symbol, and Annotation for any custom SwiftUI view, plus overlays like MapCircle and MapPolyline. In UIKit, add MKAnnotation objects to MKMapView and provide views through mapView(_:viewFor:) with reuse and clustering.

Practise saying it · 30 s. No recording, just a timer

Explain map annotations.

Say your answer out loud, then check which of these points you covered:

  • Marker vs Annotation
  • MKMapView delegate in UIKit
  • Clustering

Deep dive

Use .mapCameraKeyframeAnimator or MapCameraPosition to move the camera.

Clustering (clusteringIdentifier) keeps many pins readable.

For thousands of points, cluster or filter by the visible region.

MapPin and MapMarker are deprecated in iOS 17.

Common mistakes

  • Using deprecated MapPin.
  • Creating a new annotation view per pin without reuse.

Senior take & follow-ups

Seniors use the iOS 17 MapContent API and plan for scale.

Follow-up questions

Think of your answer first, then open the hint.

  1. How do you handle 10,000 pins?

    Show hint

    Clustering and only showing the visible region.

  2. How do you react to selection?

    Show hint

    Map(selection:) with tagged content.

Suggest a fix if something here is wrong or out of date.