In the initial Xcode 15/iOS 17 Beta selecting a Marker would give a visible indication that the marker was selected without setting the selection. This is the code I used.
struct ContentView: View {
let location = CLLocationCoordinate2D(latitude: 37.0,
longitude: -122.0)
@State private var position: MapCameraPosition = .automatic
@State private var selectedItem: MKMapItem?
var body: some View {
VStack {
Text(selectedItem == nil ? "Nothing Selected" :
selectedItem?.name == nil ? "No name" :
selectedItem!.name!)
.bold()
.padding()
Map(position: $position, selection: $selectedItem) {
Marker("Marker", coordinate: location)
.tag(1)
.tint(.red)
}
}
.padding()
}
}
I submitted feedback and things changed in Beta 3. Now I can not select the Marker. That's not the direction I'd hoped to see. Am I doing something wrong or is there no way to select a Marker placed on a map?
There seems to still be issues with how selection works, but in your case, once you designate a tag. the selection type needs to be Int to get that tag value, or at least that's what seemed to work for me based on a tutorial I've lost the link to.