Search code examples
androidparse-platformpfquerygeopoints

Query between distances in Parse


I would like to search places between two given distances, using GeoPoints. Using the currently api, I think I could make something like this pseudo algorithm:

query.whereWithinKilometers("directions", GlobalData.ownerGeoPoint, MAXIMUM distance);

MINUS

query.whereWithinKilometers("directions", GlobalData.ownerGeoPoint, MINIMUM distance);

How can I translate to real code?


Solution

  • Finally I found a way to do it with a parse query.

    // Do not want locations further than maxDistance
    ParseQuery query = ParseQuery.getQuery("MyData");
    query.whereWithinKilometers("location", userGeoPoint, maxDistance);
    
    // Do not want locations closer than minDistance
    ParseQuery<ParseObject> innerQuery = ParseQuery.getQuery("MyData");
    innerQuery.whereWithinKilometers("location", userGeoPoint, minDistance);
    query.whereDoesNotMatchKeyInQuery("objectId", "objectId", innerQuery);