iOS: Google Maps API - markerInfoWindow vs markerInfoContents

Viewed 2717

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!

2 Answers

If you want to use the default shadow effect and the anchor with markerInfoContents then you have to do it like this:

func mapView(_ mapView: GMSMapView, markerInfoContents marker: GMSMarker) -> UIView?
{
    let placeMarker = marker as! PlaceMarker
    let view = UIView(frame: CGRect.init(x: 0, y: 0, width: 150, height: 150))
    if let infoView = UIView.viewFromNibName(name: "MarkerInfoView") as? MarkerInfoView 
    {
        infoView.nameLabel.text = placeMarker.name
        view.addSubview(infoView!)
        return view
    } else {
        return nil
    }
}
Related