Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google map ios - how to keep the marker info window always displayed?

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?

like image 224
Dani Magen Avatar asked Nov 28 '25 16:11

Dani Magen


1 Answers

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.

like image 182
Shoegazing Avatar answered Nov 30 '25 07:11

Shoegazing



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!