当点击地图上的集群注释时,我试图获取集群的所有成员(IOS 11)。有人知道怎么弄吗?
以下代码添加了集群:
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
if #available(iOS 11.0, *) {
if annotation is MKClusterAnnotation {
var anView = mapView.dequeueReusableAnnotationView(withIdentifier: "cluster")
return anView
}
}
}当点击群集无法获得群集的成员时
func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) {
if #available(iOS 11.0, *) {
if view.annotation is MKClusterAnnotation {
print(view.clusteringIdentifier)
print(view.reuseIdentifier)
//*** Need array list of annotation inside cluster here ***
} else {
}
}
}获得集群成员的唯一方法是:
func mapView(_ mapView: MKMapView, clusterAnnotationForMemberAnnotations memberAnnotations: [MKAnnotation]) -> MKClusterAnnotation {
print(memberAnnotations)
return MKClusterAnnotation(memberAnnotations: memberAnnotations)
}但是无法确定哪一个是正确的点击群。
发布于 2018-03-28 07:36:08
集群具有"memberAnnotations“属性:
func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) {
if #available(iOS 11.0, *) {
if let cluster = view.annotation as? MKClusterAnnotation {
//*** Need array list of annotation inside cluster here ***
let arrayList = cluster.memberAnnotations
// If you want the map to display the cluster members
mapView.showAnnotations(cluster.memberAnnotations, animated: true)
}
}
}https://stackoverflow.com/questions/49205007
复制相似问题