Jawee
Jawee

Reputation: 145

ParseGeoLocation query

I'm currently making a android app but I ran into a bit of an issue, I'm using Parse.com as my server and I'm trying to use their ParseGeoLocation to get the current users location and compare it to the other users location using their ParseQuery. And by this i mean (Get current user location) > (Send to server object in column "location") > (Check if within other users location) > (Return other users name/data if true) I've been trying to do this correctly for the last few days but to no avail. Does anyone know how to do this? I've been searching the web but not really finding the right things. I've tried on their site "Docs" but wasn't really helpful.

Upvotes: 0

Views: 133

Answers (1)

kingspeech
kingspeech

Reputation: 1836

You can use the query whereNear constrain. You will provide your user location and call find method. This will return an array of objects ordered by distance (nearest to farthest) from your provided user location. One example code can be given as follows;

ParseGeoPoint userLocation = //current user location
ParseQuery<ParseObject> query = ParseQuery.getQuery("LocationStoredTableName");
query.whereNear("location", userLocation);
query.limit(10); //10 objects will return
query.findInBackground(new FindCallback<ParseObject>() { ... });

Hope this helps.

Regards.

Upvotes: 1

Related Questions