我有一个简单的地图视图:
@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)
}
但这根本没有被调用。为什么?
看起来好像需要设置clusteringIdentifier
对于 MKAnnotationView。这对我有用:
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
let annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: MKMapViewDefaultAnnotationViewReuseIdentifier, for: annotation)
annotationView.clusteringIdentifier = "identifier"
return annotationView
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)