Mohammad Razipour
Mohammad Razipour

Reputation: 3701

How to hide marker while showing cluster in Google Map

I use Google Map and Google-Maps-iOS-Utils for an app.

How to hide markers while showing only the cluster?

enter image description here

https://developers.google.com/maps/documentation/ios-sdk/utility/marker-clustering

Upvotes: 0

Views: 1683

Answers (3)

Muhammad Zeshan Mazhar
Muhammad Zeshan Mazhar

Reputation: 445

add one line on class GMUDefaultClusterRenderer.m

     static const NSUInteger kGMUMinClusterSize = 2;

problem resolved

Upvotes: 3

Muhammad Zeshan Mazhar
Muhammad Zeshan Mazhar

Reputation: 445

simple answer is that Go to your pod file or if you add manualy go to the class GMUDefaultClusterRenderer.m

simple is that change the top line

     static const NSUInteger kGMUMinClusterSize = 2;

your probelm resolved thanks

hope that will help you

Upvotes: 0

Mohammad Razipour
Mohammad Razipour

Reputation: 3701

import UIKit

class CustomClusterRenderer: GMUDefaultClusterRenderer {

    let GMUAnimationDuration: Double = 0.5
    var mapView: GMSMapView?

    override init(mapView: GMSMapView, clusterIconGenerator iconGenerator: GMUClusterIconGenerator) {
        super.init(mapView: mapView, clusterIconGenerator: iconGenerator)
        self.mapView = mapView
    }

    func markerWith(position: CLLocationCoordinate2D, from: CLLocationCoordinate2D, userData: AnyObject, clusterIcon: UIImage, animated: Bool) -> GMSMarker {

        let initialPosition = animated ? from : position
        let marker = GMSMarker(position: initialPosition)
        marker.userData = userData

        marker.icon = clusterIcon
        marker.groundAnchor = CGPoint(x: 0.5, y: 0.5)

        marker.map = mapView
        if animated {
            CATransaction.begin()
            CAAnimation.init().duration = GMUAnimationDuration
            marker.layer.latitude = position.latitude
            marker.layer.longitude = position.longitude
            CATransaction.commit()
        }
        return marker
    }

    func getCustomUIImageItem(userData: AnyObject) -> UIImage {
        if let item = userData as? Marker {
            return item.merkerIcon
        }
        return UIImage()
    }

    override func shouldRender(as cluster: GMUCluster, atZoom zoom: Float) -> Bool {
        print("Zoom Level is \(zoom) , and result is \(zoom<=14)")
        return zoom <= 14;
    }


}


class Marker: NSObject, GMUClusterItem {

    var position: CLLocationCoordinate2D
    var estate: Estate

    init(estate: Estate) {

        self.estate = estate
        self.position = CLLocationCoordinate2D(latitude: estate.latitude,longitude: estate.longitude)

    }

}

enter image description here

Upvotes: 1

Related Questions