Add buttons to view returned by markerInfoWindow delegate method

后端 未结 5 761
逝去的感伤
逝去的感伤 2020-11-28 08:00

I\'m currently creating and returning a custom view with the google maps ios SDK by setting delegate to self and using the following code.

#pragma mark - GMS         


        
5条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-28 08:17

    Swift 3.0 Solution

     //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()
            }
    

    and make outlet of this view(customInfoWindow) in same controller which has mapView.

    I got the idea from this link thanks to this developer Custom and interactive googlemaps(IOS SDK) infowindow

提交回复
热议问题