Search code examples
google-maps-sdk-ios

Custom annotation view in Google Maps SDK


I created an iOS application based on maps in which I thought to use Google Maps SDK for iOS instead of Mapkit, I found the documentation but it I didn’t find methods related to custom annotation view, Can anyone provide me the solution for how to create custom annotation view(info window) and how to add content(title, snippet) for it.


Solution

  • If you check GMSMapView.h within GoogleMaps.Framework, you can see the below method which should let you add a custom infowindow for a marker, instead of using standard title and snippet alone:

    NOTE you (op) say annotationView=infoWindow
    BUT NORMAL: annotationView = marker itself and calloutView = infoWindow

    /**
     * Called when a marker is about to become selected, and provides an optional
     * custom info window to use for that marker if this method returns a UIView.
     * If you change this view after this method is called, those changes will not
     * necessarily be reflected in the rendered version.
     *
     * The returned UIView must not have bounds greater than 500 points on either
     * dimension.  As there is only one info window shown at any time, the returned
     * view may be reused between other info windows.
     *
     * @return The custom info window for the specified marker, or nil for default
     */
    - (UIView *)mapView:(GMSMapView *)mapView
        markerInfoWindow:(id<GMSMarker>)marker;