View
extension View where Controls : MapControl, Self : MapAnimatableextension View where Self : MapAnimatableextension View where Self : MapAnimatable, Trigger : Equatableextension View where Self : MapContentTappable-
Adds custom controls to the map view.
Use this modifier to place controls like the compass, zoom buttons at a specific position on the map. Applying this modifier multiple times for the same position will overwrite any previously set controls for that position.
Controls are ordered from top to bottom for vertical positions (.leading, .trailing) and from left to right for horizontal positions (.top, .bottom).
Use SwiftUI’s
Spacerto push controls to one side, attach them to the opposite side, or add flexible space between them.Map(mode: .hybrid) .mapControls(at: .trailing) { CompassControl() ZoomControl() } .mapControls(at: .top) { Spacer() PanHorizontalControl() }Declaration
Swift
@MainActor @preconcurrency func mapControls<Controls>(at position: MapControlPosition = .trailing, margin: CGFloat = 16, spacing: CGFloat = 8, @MapControlsBuilder _ controls: () -> Controls) -> some MapAnimatable & ViewParameters
atThe edge of the map where the controls should be placed. Defaults to
.trailing.marginThe distance between the controls and the map edge. Defaults to
16.spacingThe distance between individual controls in the stack. Defaults to
8.controlsA result builder closure that specifies the controls to display.
-
Applies a set of restrictions to the map’s camera behavior.
Use this modifier to constrain how the user can manipulate the map’s viewpoint, ensuring it stays within defined altitude, heading, tilt, or geographical bounds. Applying an empty array removes any existing restrictions.
Map(mode: .hybrid) .cameraRestrictions([ .altitude(0...10000), // Limit zoom-out altitude .tilt(0...60) // Limit maximum tilt ])Note
If the array has more than one restriction of the same type, the last one will be used.
Declaration
Swift
@MainActor @preconcurrency func cameraRestrictions(_ restrictions: [CameraRestriction]) -> SelfParameters
restrictionsAn array of
CameraRestrictioncases defining the limits to apply to the camera’s movement and orientation.Return Value
The
Mapinstance, allowing for further modifier chaining. -
Adds a closure to be called when the map is tapped.
Declaration
Swift
@MainActor @preconcurrency func onTap(_ handler: @escaping (MapTapInfo) -> Void) -> some MapAnimatable & ViewParameters
handlerA closure that the system calls when the map is tapped. This closure receives a
MapTapInfoobject containing tap content information and geographic coordinates.
-
Fly the camera around the given center camera with the given duration and repeat count.
Declaration
Swift
@MainActor @preconcurrency func flyCameraAround<Trigger>(_ camera: Camera, duration: TimeInterval = 2, repeatCount: Double = 1, trigger: Trigger, completion: (() -> Void)? = nil) -> ModifiedContent<Self, EquatableChangeModifier<Trigger>>Parameters
cameraThe center camera to fly around.
durationThe duration of one animation cycle in seconds.
repeatCountThe number of times to fly around the center camera.
triggerThe trigger to fly the camera.
completionThe callback to be called when the animation is complete.
-
Fly the camera to the given destination camera with the given duration.
Declaration
Swift
@MainActor @preconcurrency func flyCameraTo<Trigger>(_ camera: Camera, duration: TimeInterval = 2, trigger: Trigger, completion: (() -> Void)? = nil) -> ModifiedContent<Self, EquatableChangeModifier<Trigger>>Parameters
cameraThe destination camera to fly to.
durationThe duration of the animation in seconds.
triggerThe trigger to fly the camera.
completionThe callback to be called when the animation is complete.
-
Registers a handler to be called when the map content is tapped.
Declaration
Swift
@MainActor @preconcurrency func onTap(_ handler: @escaping () -> Void) -> some MapContentParameters
handlerThe handler to be called when the map content is tapped.
-
Adds a closure to be called when a place is tapped to determine the behavior of the built-in place information plugin.
Declaration
Swift
@MainActor @preconcurrency func onPlaceTap(_ handler: @escaping (String) -> PlaceTapAction) -> some MapAnimatable & ViewParameters
handlerA closure that the system calls when a place is tapped. This closure receives the place ID and returns a
PlaceTapAction.