So I have been using Google Maps iOS SDK 4.0.0 and my requirement is like this when I tap on a marker it should add UIViewContoller's view which I easily achieved. Take a look on the following code:
var customeVC:CustomViewController?
func mapView(_ mapView: GMSMapView, didTap marker: GMSMarker) -> Bool {
customeVC = CustomViewController(nibName: "CustomViewController", bundle: nil)
customeVC?.delegate = self
self.addChild(customeVC!)
customeVC?.view.frame = self.view.frame
self.view.addSubview(customeVC!.view)
customeVC?.didMove(toParent: self)
// Remember to return false
// so marker event is still handled by delegate
return false
}
func mapView(_ mapView: GMSMapView, markerInfoWindow marker: GMSMarker) -> UIView? {
//Empty the default infowindow
return UIView()
}
extension MapViewController: CustomViewControllerDelegate {
// Triggers when I close the full screen view of CustomViewController
func didCloseWindow() {
customeVC?.willMove(toParent: nil)
customeVC?.removeFromParent()
customeVC?.view.removeFromSuperview()
customeVC = nil
}
}
Now the main the problem is, after closing the window/view if I click on the same marker again (2nd time) its doesn't show the view. But if I click once again (3rd time), it shows.
So I'm suspecting after removing the view the marker doesn't get deselected. But when I tap for the 2nd time its gets deselected and tap for the 3rd time get selected again.
I have textfields & buttons inside CustomViewController thats why I didn't add this view inside the delegate function mapView(_ mapView: GMSMapView, markerInfoWindow marker: GMSMarker) -> UIView?
. Basically I followed this article which lets you click inside InfoWindow.
I also tried to mapView.selectedMarker = marker
inside didTap
delegate method and mapView.selectedMarker = nil
when removing the view.
How do I deselect the marker so that each time I click on the same marker its should show the view?
Any help will be appreciated. Thanks in advance.