Map
A view that displays an embedded map interface.
Declaration
@MainActor @preconcurrency struct Map<Content> where Content : ViewOverview
Use this SwiftUI view to display a Map with markers, annotations, and custom content you provide. You can configure the Map to optionally display the user’s location, track a location, and display various controls to allow them to interact with and control the map’s display. The following example displays a map of downtown San Francisco that shows different markers, and an annotation with custom view content at specific locations:
struct ContentView: View {
var body: some View {
Map {
Marker("San Francisco City Hall", coordinate: cityHallLocation)
.tint(.orange)
Marker("San Francisco Public Library", coordinate: publicLibraryLocation)
.tint(.blue)
Annotation("Diller Civic Center Playground", coordinate: playgroundLocation) {
ZStack {
RoundedRectangle(cornerRadius: 5)
.fill(Color.yellow)
Text("🛝")
.padding(5)
}
}
}
.mapControlVisibility(.hidden)
}
}You create markers, annotations, and overlays using MapContentBuilder with any of several MapContent types including:
You can also add a variety of controls to allow a person to interact with the map to change the map’s scale, display or hide the device’s current location, and so on:
Topics
Creating a map
init(bounds:interactionModes:scope:)init(bounds:interactionModes:scope:content:)init(bounds:interactionModes:selection:scope:)init(bounds:interactionModes:selection:scope:)init(bounds:interactionModes:selection:scope:content:)init(bounds:interactionModes:selection:scope:content:)init(initialPosition:bounds:interactionModes:scope:)init(initialPosition:bounds:interactionModes:scope:content:)init(initialPosition:bounds:interactionModes:selection:scope:)init(initialPosition:bounds:interactionModes:selection:scope:content:)init(initialPosition:bounds:interactionModes:selection:scope:content:)init(position:bounds:interactionModes:scope:)init(position:bounds:interactionModes:scope:content:)init(position:bounds:interactionModes:selection:scope:)init(position:bounds:interactionModes:selection:scope:content:)init(position:bounds:interactionModes:selection:scope:content:)MapInteractionModes