How to add MapKit to a SwiftUI app
What MapKit does for a SwiftUI app
MapKit renders an interactive Apple Maps view: pan, zoom, pins, the user's location dot, and a camera you can point at a region. It is how a store-locator, a delivery tracker, or a travel app shows places on a map. In SwiftUI the modern Map view takes content directly, so you place Marker and Annotation views the same way you build the rest of your UI. If you need the device's location, that comes from Core Location and requires a permission prompt.
Adding it with AppFlight, and manually
In AppFlight you describe the map screen, for example pins for a list of places or a centered user location, and the AI generates the Map view, the markers, and the Core Location permission flow including the Info.plist usage string. There is no key to manage for the iOS map. If the places come from a server, AppFlight connects Supabase to load them, keeping any backend secret server-side.
Manually, you add a Map view, supply Marker or Annotation content for your coordinates, add the location usage description to Info.plist, and use a CLLocationManager to request authorization before showing the user's position.
A SwiftUI example
Show a map with a marker at a coordinate:
import MapKit
import SwiftUI
struct PlaceMap: View {
let coordinate = CLLocationCoordinate2D(
latitude: 37.3349, longitude: -122.0090)
var body: some View {
Map {
Marker("Apple Park", coordinate: coordinate)
}
.mapControls {
MapUserLocationButton()
}
}
}
Common pitfalls
Forgetting the Info.plist location usage description means the permission prompt never appears and the location dot stays hidden, since iOS requires that string. Assuming you need an API key for the iOS map is a common confusion, since the key is only for MapKit on the web or server, not the Map view. Requesting precise location when coarse would do can lower opt-in rates, so request only what the feature needs. Not handling a denied permission leaves a blank map, so center on a sensible default region when location is unavailable.
FAQ
Do I need an API key for MapKit in an iOS app?
No. MapKit is built into iOS and needs no key inside the app. A key (MapKit JS / server token) is only for MapKit on the web or server-side APIs, not the iOS Map view.
How do I show the user's location?
Add a usage description string to Info.plist, request authorization through Core Location, and once granted, MapKit can show the user's position. Without the Info.plist string and a granted permission, the location dot does not appear.
Can I add custom pins?
Yes. Use Marker for a standard pin with a label, or Annotation to place any SwiftUI view at a coordinate. Both go inside the Map view's content.