使用Swift在MapKit中进行聚类

Ric*_*oCh 5 mapkit swift

Swift中是否有可能在MapKit中聚类标记?我知道在Google Maps SDK中可以使用,但我在MapKit中找不到相同的功能.我找到了一些Obj-C的库,但没有为Swift找到

我找到的一些库:

Rob*_*hen 10

我将FBAnnotationClustering翻译为Swift:

https://github.com/ribl/FBAnnotationClusteringSwift

适用MapKit.这是一个工作示例项目,自述文件包含一些集成和使用说明.

还有一篇相关的博客文章介绍了我们为什么选择FBAnnotationClustering(我喜欢它)的背景,以及为什么我们将它翻译成Swift(如果我们以后遇到问题,不想对Objective-C进行故障排除).

http://ribl.co/blog/2015/05/28/map-clustering-with-swift-how-we-implemented-it-into-the-ribl-ios-app/

  • iOS 4中的mapkit现在支持群集. (2认同)

小智 5

使用 MKMarkerAnnotationViews 轻松聚类。这是我的类的示例,您可以在其中设置聚类标识符。

具有相同聚类标识符的注释将自动聚类。

class AnnotationView: MKMarkerAnnotationView {

    override init(annotation: MKAnnotation?, reuseIdentifier: String?) {
        super.init(annotation: annotation, reuseIdentifier: reuseIdentifier)


        self.clusteringIdentifier = "AnnotationViewIdentifier"
    }

    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }
}
Run Code Online (Sandbox Code Playgroud)