Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS: Google Maps API - markerInfoWindow vs markerInfoContents

I looked through the Google Maps docs and the description does not seem to help much.

I'm following an old tutorial that made use of markerInfoContents however, when I used the delegate it didn't return what I expected.

With markerInfoContents: My custom view seems to override the default view

enter image description here

When I used markerInfoWindow, the results were what I expected:

enter image description here

I am simply pulling in a custom UIView from a xib file like so:

func mapView(_ mapView: GMSMapView, markerInfoWindow marker: GMSMarker) -> UIView? {
    let placeMarker = marker as! PlaceMarker
    print(placeMarker.name)

    if let infoView = UIView.viewFromNibName(name: "MarkerInfoView") as? MarkerInfoView {
        infoView.nameLabel.text = placeMarker.name

        return infoView
    } else {
        return nil
    }
}

(Replace markerInfoWindow with markerInfoContents for the first image results)

With markerInfoContents it created the anchor and the shadow effect of the box. When using markerInfoWindow it does not create that anchor or shadow effect like in the tutorial.

Any help would be great!

like image 277
Simon Avatar asked May 28 '17 04:05

Simon


1 Answers

As mentioned in the documentation link posted, when using markerInfoContents: "If this method returns a view, it will be placed within the default info window frame.", so your view is constrained within the default window (that's why it shows the anchor and shadow). It looks like the default infowindow is smaller than the UIView form your xib, so it truncates it.

The use of markerInfoWindow shows the view you pass directly, so if it does not have the anchor or shadow, it will not appear.

like image 190
Efren Avatar answered Oct 20 '22 00:10

Efren