如何在Google Map中显示群集时隐藏标记

时间:2017-04-18 07:15:58

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

我使用Google Map和Google-Maps-iOS-Utils作为应用程序。

如何在仅显示群集时隐藏标记?

enter image description here

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

3 个答案:

答案 0 :(得分:1)

在GMUDefaultClusterRenderer.m类上添加一行

     static const NSUInteger kGMUMinClusterSize = 2;

问题已解决

答案 1 :(得分:0)

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

答案 2 :(得分:0)

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

简单就是改变顶线

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
    <br />
    <form>
        <div class="row">
            <div class="col-xs-12">
                <ul class="nav nav-tabs">
                  <li class="active"><a href="#">Home</a></li> 
                    <li> <a href="#">About</a> </li>
                    <li> <a href="#">Products</a> </li>
                    <li><a href="#">Login</a>  </li>
                    <li><a href="#">Trending</a>  </li>
                    <li><a href="#">Contact</a>  </li>
                </ul>
            </div> 
        </div>  
    </form>

</div>

你的问题得到了解决,谢谢

希望能帮到你