'Click on a MapAnnotation to expand view - SwiftUI
I have a MapAnnotation in SwiftUI. On user interaction with a annotation, can I display another piece of information, i.e., change the label or show additional options?
Map(coordinateRegion: $region, annotationItems: places) { place in
MapAnnotation(coordinate: place.coordinate) {
HStack {
Image(systemName: "heart.fill")
.foregroundColor(.red)
Text(place.name)
.fixedSize()
}.padding(8)
.background(Color.white)
.clipShape(RoundedRectangle(cornerRadius: 20.0, style: .continuous))
.overlay(
Image(systemName: "arrowtriangle.left.fill")
.rotationEffect(Angle(degrees: 270))
.foregroundColor(.white)
.offset(y: 10)
, alignment: .bottom)
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|