使用CloudKit CKQuery,您可以在距离上进行筛选(参见示例)。但是你怎么能在距离上排序呢?就像位置ASC。位置上的排序描述符返回一个错误:query.sortDescriptors = [NSSortDescriptor(key: "distanceToLocation", ascending: true)]:
static func getNearbySpots(location : CLLocation, completionHandler: (spots : CKRecord[]) -> Void) {
let predicate = NSPredicate(format: "distanceToLocation:fromLocation:(location, %@) < 10000", location)
let queryOperation = CKQueryOperation(query: query)
var results : CKRecord[] = []
queryOperation.recordFetchedBlock = {
results += $0
}
queryOperation.queryCompletionBlock = {
if $1 {
NSLog($1.description,[])
abort()
} else {
completionHandler(spots: results)
}
}
self.publicDB().addOperation(queryOperation)
}发布于 2014-06-23 07:06:04
好了找到了。有一个CKLocationSortDescriptor,您可以在这里指定位置。
query.sortDescriptors = [CKLocationSortDescriptor(key: "location", relativeLocation: location)]https://stackoverflow.com/questions/24360118
复制相似问题