Error Missing argument for parameter ‘placemark’ in call.
I followed a tutorial and now I’m trying to do a little bit on my own and ran into this error. The goal is to present the Markers and the Placemarkers on the Map. So if there’s a way to do it cleaner or more efficiently, or someone who can help me fix the error I’m having, I would be really thankful.
struct ContentView: View {
@Environment(.modelContext) private var modelContext
var body: some View {
TabView {
MapView()
.tabItem {
Label("Map", systemImage: "map")
}
}
}
}
#Preview {
ContentView()
.modelContainer(Placemark.preview)
}
MapView:
struct MapView: View {
@State var position: MapCameraPosition = .userLocation(fallback: .automatic)
@State private var selectedMarker: Markers?
@State private var isManualMarker = false
@Environment(.modelContext) var modelContext
@Query() private var searchPlacemarks: [Markers]
@State var placemark: Placemark
private var listPlacemarks: [Markers] {
searchPlacemarks + placemark.placemarks
}
var body: some View {
VStack{
MapReader { proxy in
Map(position: $position) {
ForEach (listPlacemarks) { pin in
Marker("", coordinate: pin.coordinate)
}
UserAnnotation()
}
.onTapGesture { position in
if isManualMarker {
if let coordinate = proxy.convert(position, from: .local) {
let markers = Markers(
name: "",
address: "",
latitude: coordinate.latitude,
longitude: coordinate.longitude
)
modelContext.insert(markers.self)
selectedMarker = markers
}
}
}
.onAppear {
CLLocationManager().requestWhenInUseAuthorization()
}
}
}
.safeAreaInset(edge: .bottom) {
HStack {
Toggle(isOn: $isManualMarker) {
Label("Marker placement is: (isManualMarker ? "ON" : "OFF")", systemImage: isManualMarker ? "mappin.circle" : "mappin.slash.circle")
}
.fontWeight(.bold)
.toggleStyle(.button)
.background(.ultraThinMaterial)
.onChange(of: isManualMarker) {
}
.cornerRadius(4)
}
.padding()
}
}
New contributor
Luke is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
5