首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >iOS 11集群成员

iOS 11集群成员
EN

Stack Overflow用户
提问于 2018-03-10 03:23:39
回答 1查看 1.2K关注 0票数 6

当点击地图上的集群注释时,我试图获取集群的所有成员(IOS 11)。有人知道怎么弄吗?

以下代码添加了集群:

代码语言:javascript
复制
    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
            }
        }
    }

当点击群集无法获得群集的成员时

代码语言:javascript
复制
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 {

         }
     }
}

获得集群成员的唯一方法是:

代码语言:javascript
复制
func mapView(_ mapView: MKMapView, clusterAnnotationForMemberAnnotations memberAnnotations: [MKAnnotation]) -> MKClusterAnnotation {

    print(memberAnnotations)

    return MKClusterAnnotation(memberAnnotations: memberAnnotations)
}

但是无法确定哪一个是正确的点击群。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-03-28 07:36:08

集群具有"memberAnnotations“属性:

代码语言:javascript
复制
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)

    }
  }
}
票数 8
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49205007

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档