iosswiftgoogle-mapsswiftui

Delegate function not being called when tapping a poi using the gms and swift ui


So I implemented the google maps sdk in swiftui and for some reason the the delegate function mapView(_:didTapPOIWithPlaceID:name:location:) is not being called, but the function func mapView(_ mapView: GMSMapView, didTapAt coordinate: CLLocationCoordinate2D) is. I am tapping pois. So I really do not now what I'm doing wrong.

override func viewDidLoad() {
        super.viewDidLoad()
     let options = GMSMapViewOptions()
     options.frame = self.view.bounds;
        
     let mapView = GMSMapView(options:options)
     mapView.settings.myLocationButton = true
     mapView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
     mapView.isMyLocationEnabled = true
     mapView.delegate = self
     self.view.addSubview(mapView)
     self.mapView = mapView

}

func mapView(_ mapView: GMSMapView, didTapPOIWithPlaceID placeID: String, name: String, location: CLLocationCoordinate2D) {
        // Not being called
        infoMarker.snippet = placeID
        infoMarker.position = location
        infoMarker.title = name
        infoMarker.opacity = 0;
        infoMarker.infoWindowAnchor.y = 1
        infoMarker.map = mapView
        mapView.selectedMarker = infoMarker
        
    }
      

Solution

  • I've had the same issue while using Maps SDK 9.0.0 and reverting back to 8.4.0 resolved it. It seems to be a bug on Google's end. I should probably write them a ticket