如何阻止 MKClusterAnnotation 显示标注

问题描述

问题:如何防止 MKClusterAnnotation 显示标注?

背景:我是编程的初学者,请保持温和。我正在尝试制作一个基于 MapKit 的应用程序,它在地图上显示了许多站点。我已经用 GeoJSON 中的虚拟位置填充了地图,效果很好。然而,虽然标注从单个注释中有意义,但我不希望它们出现在集群注释中。我一直无法弄清楚如何从集群中删除标注。

我的注释是这样创建的:

    func mapView(_ mapView: MKMapView,viewFor annotation: MKAnnotation) -> MKAnnotationView? {
        
       if annotation is MKUserLocation {
       return nil
        } else {
            
            let identifier = "site"
            var marker: MKMarkerAnnotationView
            
            if let dequeuedView = mapView.dequeueReusableAnnotationView(
                withIdentifier: identifier) as? MKMarkerAnnotationView {
                dequeuedView.annotation = annotation
                marker = dequeuedView
                                
            } else {
                marker = MKMarkerAnnotationView(annotation: annotation,reuseIdentifier: identifier)
            }
            
            marker.canShowCallout = true // How can I turn this false if callout is a cluster?
            marker.markerTintColor = .systemBlue
            marker.rightCalloutAccessoryView = UIButton(type: .detailDisclosure)
            marker.glyphImage = UIImage(systemName: "star")
            marker.clusteringIdentifier = "clusteringIdentifier"
            
            return marker
            
        }
    }

这是我的 MKClusterAnnotation:


    func mapView(_ mapView: MKMapView,clusterAnnotationForMemberAnnotations memberAnnotations: [MKAnnotation]) -> MKClusterAnnotation {

        let cluster = MKClusterAnnotation(memberAnnotations: memberAnnotations)
        cluster.title = "More things to see here"
        cluster.subtitle = "Zoom further in"
        return cluster
        
    }

这可能非常简单,但我无法自己(或通过查看 Apple 文档)找到它。任何帮助表示赞赏! (另外,如果您在我的代码中看到任何愚蠢的地方,请不要害怕指出)。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)