具有集群的MapView:如何在同一个视图上显示多个注释

我已经在mkmapview上集成了FBAnnotationClustering ,它完美地工作,但是当在同一个地方有多个注释时,我不能用正确的信息显示annotationView。 我试图通过注释循环,并显示在相同的视图(每个与标注button显示更多信息)。

到目前为止,我设法做一个标注工作,以显示底部的细节,但在注解视图显示它没有正确的标题,只有一个,所以它不是很有用。 所以我想知道,是否有可能在同一个视图上显示多个注释? 任何想法我怎么能实现这个?

带有单个注释的地图与群集视图的地图

这是我的集群类:

 class FBAnnotationCluster : NSObject { var coordinate = CLLocationCoordinate2D(latitude: 39.208407, longitude: -76.799555) var title:String = "cluster" var subtitle:String? = nil var annotations:[FBAnnotation] = [] } 

我的单个注释类:

 class FBAnnotation : NSObject { var coordinate: CLLocationCoordinate2D var id: Int var title: String var subtitle: String var distance: String init(id: Int, title: String, subtitle: String, distance: String, coordinate: CLLocationCoordinate2D){ self.id = id self.title = title self.subtitle = subtitle self.distance = distance self.coordinate = coordinate } } 

viewForAnnotation

 func mapView(mapView: MKMapView!, viewForAnnotation annotation: MKAnnotation!) -> MKAnnotationView! { var reuseId = "" if annotation.isKindOfClass(FBAnnotationCluster) { reuseId = "Cluster" var clusterView = mapView.dequeueReusableAnnotationViewWithIdentifier(reuseId) clusterView = FBAnnotationClusterView(annotation: annotation, reuseIdentifier: reuseId) if mapView.zoomLevel() >= 15 { println("Display annotation list") let a = annotation as! FBAnnotationCluster if a.annotations.count > 1 { for annotation in a.annotations { println(annotation.title) clusterView!.enabled = true clusterView!.canShowCallout = true //we add an info button to display the detailed view clusterView!.calloutOffset = CGPoint(x: -5, y: 5) clusterView!.rightCalloutAccessoryView = UIButton.buttonWithType(.DetailDisclosure) as! UIView clusterView!.tag = annotation.id } } } return clusterView } else { reuseId = "Pin" var pinView = mapView.dequeueReusableAnnotationViewWithIdentifier(reuseId) as? MKPinAnnotationView pinView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: reuseId) pinView!.enabled = true pinView!.canShowCallout = true //we add an info button to display the detailed view pinView!.calloutOffset = CGPoint(x: -5, y: 5) pinView!.rightCalloutAccessoryView = UIButton.buttonWithType(.DetailDisclosure) as! UIView pinView!.image = UIImage(named: "map-annotation") let a = annotation as! FBAnnotation pinView!.tag = a.id return pinView } } 

是的,如果你的点位置具有相同的经纬度,那么你将不能单独显示所有的点。 你可以试试黑客。 您可以将所有具有相同经纬度的点的列表分开,并在将其应用于聚类之前,将其中一个纬度值更改为+或 – 0.00007并创build一个模式。 显示效果不会很大,你可以在集群中显示你所有的点。