我试图让我在自定义区域中的每个CKRecord单独显示在我的地图上作为注释。我使用注释标题和副标题作为CKRecord中的其他字段,但对于annotation.cordinate,我很难将其连接到CKRecord"位置"领域。
func fetchTruck() {
let truePredicate = NSPredicate(value: true)
let eventQuery = CKQuery(recordType: "User", predicate: truePredicate)
let queryOperation = CKQueryOperation(query: eventQuery)
queryOperation.recordFetchedBlock = { (record : CKRecord!) in
self.truck.append(record)
let annotation = MKPointAnnotation()
annotation.title = record["username"] as? String
annotation.subtitle = record["hours"] as? String
**if let location = record["location"] as? CLLocation {
annotation.coordinate = location.coordinate}** Answer
print("recordFetchedBlock: \(record)")
self.mapView.addAnnotation(annotation)
}
queryOperation.queryCompletionBlock = { (cursor, error) in
print("queryCompletionBlock: \(self.truck)")
}
database.add(queryOperation)
}
override func viewDidLoad() {
super.viewDidLoad()
fetchTruck()
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.requestWhenInUseAuthorization()
locationManager.startUpdatingLocation()
}
答案 0 :(得分:1)
您的CKRecord
将有一个位置字段。这将是CLLocation
类型的值。
coordinate
的{{1}}属性属于MKPointAnnotation
。
CLLocationCoordinate2D
的{{1}}属性也属于CLLocation
类型。
coordinate