当点击地图上的集群注释时,我试图获取集群的所有成员(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
}
}
}
Run Code Online (Sandbox Code Playgroud)
当点击集群时无法获得集群成员
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 {
}
}
}
Run Code Online (Sandbox Code Playgroud)
获取集群成员的唯一方法是:
func mapView(_ mapView: MKMapView, clusterAnnotationForMemberAnnotations memberAnnotations: [MKAnnotation]) -> MKClusterAnnotation {
print(memberAnnotations)
return MKClusterAnnotation(memberAnnotations: memberAnnotations)
}
Run Code Online (Sandbox Code Playgroud)
但无法确定哪一个是正确的抽头集群
集群有一个“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)
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1118 次 |
| 最近记录: |