iOS 11个集群成员
iOS 11 Cluster member
我在点击地图上的集群注释时试图获取集群的所有成员(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)
}
但无法确定哪个是正确的抽头簇
集群有 "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)
}
}
}
我在点击地图上的集群注释时试图获取集群的所有成员(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)
}
但无法确定哪个是正确的抽头簇
集群有 "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)
}
}
}