Im trying to pin the locations on the mapview but the errors keep coming up
I tried adding all the PinItem to the annotationItems but that doesn't work
struct Store_locator_page: View {
struct PinItem: Identifiable{
let id = UUID()
let coordinate: CLLocationCoordinate2D
}
@State var region = MKCoordinateRegion(center:.init(latitude: -32.5, longitude: 115.75),latitudinalMeters: 1000, longitudinalMeters: 1000)
let locations = [
PinItem(coordinate: .init(latitude: -32.5, longitude: 115.75)),
PinItem(coordinate: .init(latitude: -32.7, longitude: 115.9)),
PinItem(coordinate: .init(latitude: -32.6, longitude: 115.8)),
PinItem(coordinate: .init(latitude: -32.4, longitude: 115.7))
]
var body: some View {
ScrollView{
Map(coordinateRegion : $region,
interactionModes: [],
showsUserLocation: true,
userTrackingMode: nil,
annotationItems: [PinItem(coordinate: .init(latitude: -32.5, longitude: 115.75))]
) { item in
MapMarker(coordinate: item.coordinate)
}
}
}
}
Use the following technique to append multiple pins to the Map view.