Custom info window in IOS google maps sdk

前端 未结 4 1076
自闭症患者
自闭症患者 2020-12-21 06:41

being a newby IOS developer, I\'m really struggling to get something basic to work.

I have a need to display this kind of custom info window upon a marker click in t

4条回答
  •  天涯浪人
    2020-12-21 07:13

    Swift 3.0 Solution

    Google Map CustomInfoWindow

    //empty the default infowindow
        func mapView(_ mapView: GMSMapView, markerInfoWindow marker: GMSMarker) -> UIView? {
            return UIView()
        }
    
        // reset custom infowindow whenever marker is tapped
        func mapView(_ mapView: GMSMapView, didTap marker: GMSMarker) -> Bool {
    
            customInfoView.removeFromSuperview()
        //    customInfoView.button.addTarget(self, action: #selector(buttonTapped(_:)), for: .touchUpInside)
            self.view.addSubview(customInfoView)
    
            // Remember to return false
            // so marker event is still handled by delegate
            return false
        }
    
        // let the custom infowindow follows the camera
        func mapView(_ mapView: GMSMapView, didChange position: GMSCameraPosition) {
            if (locationMarker != nil){
                let location = locationMarker.position
                customInfoView.center = mapView.projection.point(for: location)
            }
        }
    
        // take care of the close event
        func mapView(_ mapView: GMSMapView, didTapAt coordinate: CLLocationCoordinate2D) {
            customInfoView.removeFromSuperview()
        }
    

提交回复
热议问题