I'm trying to keep the info window from disappearing. To show it I've used
[mapView_ setSelectedMarker:marker];
But when the user taps the map somewhere the info window disappears. I've tried re-setting it at didTapAtCoordinate but this is called before deselecting any markers. How to do it?
For anyone wanting to test out Hanton's solution in Swift 4, simplified to just always show the info window as soon as the page is loaded:
override func viewDidLoad() {
mapView.addObserver(self, forKeyPath: "selectedMarker", options: [.new, .old], context: nil)
}
override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
if keyPath == "selectedMarker" {
if change?[.newKey] as? NSObject is NSNull {
mapView.selectedMarker = change?[.oldKey] as? GMSMarker
}
}
}
This does work, though there is a brief flash of the info window disappearing and reappearing when the user taps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With