Contents

Map

A view that displays an embedded map interface.

Declaration

@MainActor @preconcurrency struct Map<Content> where Content : View

Overview

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

Deprecated

Displaying place information

Initializers

See Also

Essentials