Custom info window in IOS google maps sdk

喜你入骨 提交于 2019-11-29 15:09:07
Naresh Reddy M

I was suffering from the same problem of Info window customization in GoogleMapsSdk for iOS for a lot of days, got frustrated & did it my self!

Clean, Completely customizable & Own UIControls with your custom actions code can be found on Github Right here

Happy coding :)

Dipen Desai

Make Xib as you want...set Text and image

set delegate GMSMapViewDelegate

-(UIView *)mapView:(GMSMapView *)mapView markerInfoWindow:(GMSMarker *)marker{

    CustomInfoWindow *infoWindow=[[[NSBundle mainBundle] loadNibNamed:@"InfoWindow" owner:self options:nil] objectAtIndex:0];  
     return infoWindow;

}

https://www.youtube.com/watch?v=ILiBXYscsyY for more help see this video..Uploded by google

ended up using SMCalloutView @ https://github.com/nfarina/calloutview

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