I think they are called callouts.
I want to create custom map annotations using swiftUI Views in the map this is the code i'm using:
The custom map Annotation uses the view "EventMapAnnotation" to show a yellow circle that I'm using to test as a button. Now I want this button or this Annotation to show me a window or a view with more details about the location.
I've heard of something called a "Callout" But im not sure if the pure SwiftUI map supports it yet.
I want to create custom map annotations using swiftUI Views in the map this is the code i'm using:
Code Block Swift Map(coordinateRegion: $coordinateStart, interactionModes: interactionMode, showsUserLocation: true, userTrackingMode: $trackingMode, annotationItems: locations, annotationContent:{(location)in MapAnnotation(coordinate: location.coordinate){ EventMapAnnotation()} })
The custom map Annotation uses the view "EventMapAnnotation" to show a yellow circle that I'm using to test as a button. Now I want this button or this Annotation to show me a window or a view with more details about the location.
I've heard of something called a "Callout" But im not sure if the pure SwiftUI map supports it yet.
You can create your own custom AnnotationViews using the MapAnnotation. See below an example that creates a callout with an image.
Where AssetAnnotationView could look like this:
callout is a custom modifier here that draws the callout shape (a rounded rect with a beak/point to the bottom of the view)
Code Block Map(coordinateRegion: $coordinateRegion, annotationItems: annotations) { annotation in MapAnnotation(coordinate: annotation.coordinate, anchorPoint: CGPoint(x: 0.5, y: 1)) { AssetAnnotationView(image: annotation.image) } }
Where AssetAnnotationView could look like this:
Code Block struct AssetAnnotationView: View { var image: UIImage var body: some View { Image(uiImage: image) .resizable() .aspectRatio(contentMode: .fill) .frame(width: 100, height: 100) .cornerRadius(3.0) .padding(4) .callOut() } } }
callout is a custom modifier here that draws the callout shape (a rounded rect with a beak/point to the bottom of the view)