【发布时间】:2015-07-21 11:12:19
【问题描述】:
我已经在mkmapview 上集成了FBAnnotationClustering,它运行良好,但是当在完全相同的位置有多个注释时,我无法显示具有正确信息的annotationView。我正在尝试遍历注释并将它们显示在同一个视图中(每个视图都有一个标注按钮以显示更多信息)。
到目前为止,我设法使一个标注工作以在底部显示详细信息,但在 annotationView 中它显示它时没有正确的标题,而且只有一个,所以它并不完全有用。所以我想知道,是否可以在同一个视图上显示多个注释?知道如何实现这一目标吗?
这是我的集群类:
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
}
}
【问题讨论】:
标签: ios swift mkmapview mkannotation mkannotationview