【问题标题】:How to hide marker while showing cluster in Google Map如何在谷歌地图中显示集群时隐藏标记
【发布时间】:2017-09-13 22:10:30
【问题描述】:

我将 Google Map 和 Google-Maps-iOS-Utils 用于应用。

如何在只显示集群的同时隐藏标记?

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

【问题讨论】:

标签: ios swift google-maps google-maps-markers markerclusterer


【解决方案1】:
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)

    }

}

【讨论】:

    【解决方案2】:

    简单的答案是转到您的 pod 文件,或者如果您手动添加,请转到 GMUDefaultClusterRenderer.m 类

    简单的就是改变顶行

         static const NSUInteger kGMUMinClusterSize = 2;
    

    您的问题已解决,谢谢

    希望对你有帮助

    【讨论】:

      【解决方案3】:

      在 GMUDefaultClusterRenderer.m 类上添加一行

           static const NSUInteger kGMUMinClusterSize = 2;
      

      问题已解决

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-01-13
        • 1970-01-01
        • 1970-01-01
        • 2013-01-02
        • 2023-03-19
        • 1970-01-01
        • 2013-03-24
        相关资源
        最近更新 更多