MapMarker
A balloon-shaped annotation used to indicate the location on a map.
Declaration
struct MapMarkerOverview
Create a Map and display marker annotations by returning a view that conforms to MapAnnotationProtocol, such as MapMarker, from the trailing closure of init(coordinateRegion:interactionModes:showsUserLocation:userTrackingMode:annotationItems:annotationContent:) or init(mapRect:interactionModes:showsUserLocation:userTrackingMode:annotationItems:annotationContent:). Items you provide as a collection to the source annotations need to conform to Identifiable.
For example, the following code displays a map with a marker annotation:
struct IdentifiablePlace: Identifiable {
let id: UUID
let location: CLLocationCoordinate2D
init(id: UUID = UUID(), lat: Double, long: Double) {
self.id = id
self.location = CLLocationCoordinate2D(
latitude: lat,
longitude: long)
}
}
struct PinAnnotationMapView: View {
let place: IdentifiablePlace
@State var region: MKCoordinateRegion
var body: some View {
Map(coordinateRegion: $region,
annotationItems: [place])
{ place in
MapMarker(coordinate: place.location,
tint: Color.purple)
}
}
}