我试图用自定义注释将我的mapview聚集,但从未调用群集。这是我的代码:
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
if annotation is MKUserLocation{
return nil
}
let an = MKAnnotationView.init(annotation: annotation, reuseIdentifier: "AD")
an.clusteringIdentifier = (annotation as! StopAnnotation).id!.joined(separator: "_")
an.image = #imageLiteral(resourceName: "face")
return an
}
这从来没有触发聚类,我还实施了此代表:
func mapView(_ mapView: MKMapView, clusterAnnotationForMemberAnnotations memberAnnotations: [MKAnnotation]) -> MKClusterAnnotation {
return MKClusterAnnotation(memberAnnotations: memberAnnotations)
}
也从未被调用。我在做什么错?
确保每个群集并不是唯一的clusteringIdentifier
。由于您通过(annotation as! StopAnnotation).id!
,我猜这是Uniq。
来自Apple文档:
当多个注释视图之间存在碰撞与地图表面上具有相同标识符的碰撞时,会发生聚类。
您可以在此处阅读更多。