I am using the new Map API in SwiftUI but am running into a problem. I would like to show names and perhaps an action button in a small popup when a pin is tapped, but can't seem to find out how to do this. XCode recommends me an onTapGesture argument in the MapPin, but writing code in it gives me the "Extra argument in call" error. Here is the code for my map and pins.
@State private var GPsNear = [
AnnotatedItem(name: "Times Square", coordinate: .init(latitude: 40.75773, longitude: -73.985708)),
AnnotatedItem(name: "Flatiron Building", coordinate: .init(latitude: 40.741112, longitude: -73.989723)),
AnnotatedItem(name: "Empire State Building", coordinate: .init(latitude: 40.748817, longitude: -73.985428))
]
@State private var region: MKCoordinateRegion = MKCoordinateRegion(center: CLLocationCoordinate2D(latitude: 40.75773, longitude: -73.985708), span: MKCoordinateSpan(latitudeDelta: 0.05, longitudeDelta: 0.05))
var body: some View {
Map(coordinateRegion: $region, interactionModes: [], showsUserLocation: true, annotationItems: GPsNear) { item in
MapPin(coordinate: item.coordinate, tint: .red)
}
.edgesIgnoringSafeArea(.all)
.onAppear(perform: askForPermission)
}
struct AnnotatedItem: Identifiable {
let id = UUID()
var name: String
var coordinate: CLLocationCoordinate2D
}
I look forward to hearing any answer