i want to find locations within a range based on some fields in the location model:
The fields below are pre-calculated before the query.
let CUR_cos_lat = cos(currenLocation.latitude * .pi / 180)
let CUR_sin_lat = sin(currenLocation.latitude * .pi / 180)
let CUR_cos_lng = cos(currenLocation.longitude * .pi / 180)
let CUR_sin_lng = sin(currenLocation.longitude * .pi / 180)
let cos_allowed_distance = cos(2.0 / 6371)
i want to write a query like the below in Swift CoreData using NSPredicate:
SELECT * FROM position WHERE CUR_sin_lat * sin_lat + CUR_cos_lat * cos_lat * (cos_lng*
CUR_cos_lng + sin_lng * CUR_sin_lng) > cos_allowed_distance;
The fields below in the query above are already available in the CoreData model,
- sin_lat
- cos_lat
- cos_lng
- sin_lng
- cos_allowed_distance
Link to Question on Stack : https://stackoverflow.com/questions/66634089/arithmetic-calculations-with-fields-of-coredata-models-with-nspredicate