Skip to content

Is there anyway i can use QueryKit to solve the problem below  #62

Description

@yawboafo

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,

  1. sin_lat
  2. cos_lat
  3. cos_lng
  4. sin_lng
  5. cos_allowed_distance

Link to Question on Stack : https://stackoverflow.com/questions/66634089/arithmetic-calculations-with-fields-of-coredata-models-with-nspredicate

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions