iOS: Google Maps API - markerInfoWindow vs markerInfoContents

孤者浪人 提交于 2019-12-03 00:33:53

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.

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
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!