Contents

mapControls(_:)

Configures all Map views in the associated environment to have standard size and position controls

Declaration

@MainActor @preconcurrency func mapControls(@ViewBuilder _ content: () -> some View) -> some View

Parameters

  • content:

    A view builder returning the controls you wish your Map

Discussion

You provide the controls you want to appear atop your map. When using a control in conjunction with .mapControls you don’t need to specify a scope. Views that are not MapKit controls will be ignored.

Map()
.mapControls {
    MapScaleView()
    MapUserLocationButton()
}

Controls can be modified individually or all at once. Custom frames and alignments set on controls are ignored.

Map()
.mapControls {
    MapCompass()
        .mapControls(.visible)
    MapPitchToggle()
        .buttonBorderShape(.circular)
        .tint(.purple)
}
.controlSize(.large)

On watchOS, space is at a premium. When using the mapControls modifier, MapUserLocationButton and MapCompass are automatically combined if present.

Map()
.mapControls {
    MapUserLocationButton()
    MapCompass()
}

See Also

Getting location information