为什么不调用MKMapView中的clusterAnnotationForMemberAnnotations? [英] Why clusterAnnotationForMemberAnnotations in MKMapView is not called?

查看:397
本文介绍了为什么不调用MKMapView中的clusterAnnotationForMemberAnnotations?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的地图视图:

I have a simple 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)
}

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

but this is not called at all. Why?


推荐答案

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

It appears as though it is required to set the clusteringIdentifier for the MKAnnotationView. This has worked for me:

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

这篇关于为什么不调用MKMapView中的clusterAnnotationForMemberAnnotations?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆