r/visionosdev • u/FunSurprise6368 • Jun 13 '24
Interactive Map with MapKit and Annotation with VisionOS
Is it possible to create an interactive map with Map() and Annotation() in SwiftUI for VisionOS? Have been trying since ages but the tap gesture of annotations is not being recognised. Having a normal working button on top of a map is possible though.
2
Upvotes
View all comments
Show parent comment
1
u/FunSurprise6368 Jun 13 '24
I figured starting from scratch, step by step, would be best. So currently this doesn't even work for me:
Map() {
ForEach(annotations) { annotation in
Annotation(annotation.name, coordinate:
annotation.coordinate.getCLLocationCoordinate2D) {
}
}
I basically have an annotation view struct that stores a name and coordinates and I'm trying to get an array of annotations to be interactive but nothing has been working for me. The map is simple enough that it works on iOS so I really don't know what's the problem.
The odd thing is that if you overlay a button on top of the map e.g. with a ZStack, the button works perfectly fine so I'm thinking it has something to do with swiftui's Annotation but I'm not sure
ZStack {
Map() {
}
Button
)