使用 Swift 在 MapKit 中进行聚类
Clustering in MapKit with Swift
在Swift中是否可以在MapKit中对标记进行聚类?
我知道在 Google Maps SDK 中是可能的,但我在 MapKit 中找不到相同的功能。
我找到了一些用于 Obj-C 的库,但没有找到 Swift
我找到的一些库:
我运行将 FBAnnotationClustering 指定为 Swift:
https://github.com/ribl/FBAnnotationClusteringSwift
与 MapKit
一起工作。这是一个工作示例项目,自述文件包含一些集成和使用说明。
还有一个相关的博客 post 介绍了我们为什么选择 FBAnnotationClustering(我喜欢它)的背景,以及为什么我们 运行 将它定为 Swift(感觉不到如果我们稍后 运行 遇到问题,例如排除故障 Objective-C)。
使用 MKMarkerAnnotationViews 轻松聚类。这是我的 class 示例,您可以在其中设置聚类标识符。
具有相同聚类标识符的注释将自动聚类。
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)
}
}
在Swift中是否可以在MapKit中对标记进行聚类? 我知道在 Google Maps SDK 中是可能的,但我在 MapKit 中找不到相同的功能。 我找到了一些用于 Obj-C 的库,但没有找到 Swift
我找到的一些库:
我运行将 FBAnnotationClustering 指定为 Swift:
https://github.com/ribl/FBAnnotationClusteringSwift
与 MapKit
一起工作。这是一个工作示例项目,自述文件包含一些集成和使用说明。
还有一个相关的博客 post 介绍了我们为什么选择 FBAnnotationClustering(我喜欢它)的背景,以及为什么我们 运行 将它定为 Swift(感觉不到如果我们稍后 运行 遇到问题,例如排除故障 Objective-C)。
使用 MKMarkerAnnotationViews 轻松聚类。这是我的 class 示例,您可以在其中设置聚类标识符。
具有相同聚类标识符的注释将自动聚类。
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)
}
}