You can create your own custom AnnotationViews using the MapAnnotation. See below an example that creates a callout with an image.
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:
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)
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags: