ios - 为什么不调用 MKMapView 中的 clusterAnnotationForMemberAnnotations?

标签 ios swift mapkit

我有一个简单的 map View :

@IBOutlet private var mapView: MKMapView!

然后我一个一个的添加注解:

mapView.addAnnotation(Annotation(user: user))

并全部显示:

mapView.showAnnotations(mapView.annotations, animated: true)

我也实现了方法:

func mapView(_ mapView: MKMapView, clusterAnnotationForMemberAnnotations memberAnnotations: [MKAnnotation]) -> MKClusterAnnotation {
    print(memberAnnotations)
    return MKClusterAnnotation(memberAnnotations: memberAnnotations)
}

但这根本没有被调用。为什么?

enter image description here enter image description here

最佳答案

似乎需要为 MKAnnotationView 设置 clusteringIdentifier。这对我有用:

func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
    let annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: MKMapViewDefaultAnnotationViewReuseIdentifier, for: annotation)
    annotationView.clusteringIdentifier = "identifier"
    return annotationView
}

关于ios - 为什么不调用 MKMapView 中的 clusterAnnotationForMemberAnnotations?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47914910/

相关文章:

ios - 没有看到任何官方文档 - 我们可以在应用程序中保留 showFeaturePoint 吗?

ios - Xcode 7.0 测试版 6 : Issue with VectorKit

ios - CLGeocoder 可以在美国以外的全局范围内使用吗?

ios - 如何摆脱导航栏和手机顶部之间的空间

ios - 在 iphone 中将相机/照片库图像文件大小减少到 100 KB 以下

ios - 无法使计时器 swift 失效

ios - 在 Mapkit 中使用卫星 View 有什么缺点吗?

ios - 是否有提供交通信息的适用于 iOS 的 Google Maps API?

ios - 之间传递数据

ios - 如何使用 makehuman、blender 和 PVRShaman 在 Cocos3d 中正确显示 3d 模型?