【发布时间】:2021-02-22 21:28:05
【问题描述】:
问题:如何防止 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 文档)。任何帮助表示赞赏! (另外,如果您在我的代码中看到任何愚蠢的东西,请不要害怕指出)。
【问题讨论】:
标签: swift mapkit mkannotation mkclusterannotation