Is there an issue with distanceToLocation:fromLocation CloudKit predicate?
I am trying to fetch some results from cloud db using the following code:
CGFloat radius = 1000.00; // in meters
CLLocation *currentLocation =
[[CLLocation alloc] initWithLatitude:42.713834 longitude:23.264086];
CKLocationSortDescriptor *sortDescriptor =
[[CKLocationSortDescriptor alloc] initWithKey:@"location" relativeLocation:currentLocation];
[NSPredicate predicateWithFormat:@"distanceToLocation:fromLocation:(location, %@) < %f",
currentLocation, radius];
I am expecting four records but result contains seven. Three of them exceed my predicate rule.
Result:
lat:42.713402 long:23.275190 distance:910.919712
lat:42.710781 long:23.271160 distance:671.444867
lat:42.734921 long:23.247850 distance:2693.570884
lat:42.724411 long:23.281340 distance:1837.812711
lat:42.721882 long:23.270849 distance:1051.719189
lat:42.714920 long:23.263790 distance:123.055994
lat:42.715111 long:23.261801 distance:234.863830
Distance in the result above was measured for every record with:
[[record objectForKey:@"location"] distanceFromLocation:currentLocation];
Sort descriptor also does not work properly.
By documentation sort descriptor should sort results in ascending order - but it is not true