我有一个简单的 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)
}
但这根本没有被调用。为什么?
最佳答案
似乎需要为 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/