Hi, asking this here because this is not about google maps ios sdk issue but regarding the use of binding.
My map view currently looks simple.
import SwiftUI
import GoogleMaps
import GoogleMapsUtils
struct MapView: UIViewRepresentable {
var geoJsonParser: GMUGeoJSONParser?
func makeUIView(context: Self.Context) -> GMSMapView {
let mapView = GMSMapView.map(withFrame: CGRect.zero, camera: GMSCameraPosition())
mapView.delegate = context.coordinator
return mapView
}
func updateUIView(_ mapView: GMSMapView, context: Context) {
mapView.clear()
if let geoJsonParser {
print(geoJsonParser.features)
}
}
func makeCoordinator() -> Coordinator {
Coordinator(owner: self)
}
}
class Coordinator: NSObject, GMSMapViewDelegate {
let owner: MapView
init(owner: MapView) {
self.owner = owner
}
func mapView(_ mapView: GMSMapView, didTapAt coordinate: CLLocationCoordinate2D) {
print("tapped at coordinate")
print(owner)
}
}
class Coordinator: NSObject, GMSMapViewDelegate {
let owner: MapView
init(owner: MapView) {
self.owner = owner
}
func mapView(_ mapView: GMSMapView, didTapAt coordinate: CLLocationCoordinate2D) {
print("tapped at coordinate")
print(owner.geoJsonParser)
}
}
My question is when i tap on the map, the mapView didTapAtCoordinate gets called but the geoJsonParser variable is always nil. So I thought i would use Binding in this case since when the MapView struct is used, I pass a @State geoJsonParser to its parameter.
My question is, from within the MapView struct, I am not sure what else I could be lacking so that print(owner.geoJsonParser) will not return nil
I tried to set the variable to var geoJsonParser: Binding? = nil
But after tapping on the map and the mapView didTapAtCoordinate is called, print(owner.geoJsonParser) returns an error
Cannot convert value of type 'Binding<[any GMUGeometryContainer]>' to expected argument type '[any GMUGeometryContainer]'
Same error message in the print statement in updateUIView(). Any idea what could be wrong here?
My goal is to have owner.geoJsonFeature not be nil.