CloudKit areas closest to the points

I am looking for a query for CloudKit that can return me objects with the objects closest to my location, sorted by distance. So far I can get places at a certain distance from my point.

NSPredicate(format: "distanceToLocation:fromLocation:(%K,%@) < %f","Location",location,radiusInKilometers)

But that is not what I need. What I'm looking for is locations sorted from the nearest one, the radius does not matter to me, so the decision to use this query and sort the results on my device is not suitable for me. Any help?

+4
source share
1 answer

CKLocationSortDescriptor sortDescriptors resultsLimit. , , (, 5).

queryOperation.sortDescriptors = [CKLocationSortDescriptor(key: "location", relativeLocation: location)]
queryOperation.resultsLimit = 5
+2

All Articles