Search code examples
iosswiftswift3google-maps-markersgoogle-maps-sdk-ios

how can I set custom marker icon with markers cluster in iOS Swift


I have try to use mapView() function and only when I click on the marker, that choose marker will change to custom marker icon. How can I change the default marker (WITH CLUSTERING).

func mapView(_ mapView: GMSMapView, didTap marker: GMSMarker) -> Bool {

        let poiItem = marker.userData as? POIItem
        marker.title = poiItem?.devname
        marker.snippet = poiItem?.address
        marker.icon = UIImage(named: "runcar1")
        return false
}

image


Solution

  • 1 : GO to Poitem class

    Add one more element to that class

     let marker = GMSMarker()
    

    add that in init method too

    and then simple called

     let myitem = POitem() 
     myitem.marker = GMSMarker(latitude:0,longitude:0)
     self.map.add(myitem)