Narcis
Narcis

Reputation: 236

Parse geo query is always empty

I'm working on an Android app that, among other features, detects places in the user's proximity. For this, I use a Parse Query based on the example from the Anywall app. The problem is that the result of this query is always empty, even though my database is populated. Here is my code:

private static final int MAX_SEARCH_DISTANCE = 150;
private static final int MAX_SEARCH_LIMIT = 10;
ParseGeoPoint userLocation = new ParseGeoPoint(Double.valueOf("23.0465320"), Double.valueOf("72.5925700"));
ParseQuery<VevantoParse> mapQuery = VevantoParse.getQuery();
mapQuery.whereWithinKilometers("location", userLocation, MAX_SEARCH_DISTANCE);

And the class that extends ParseObject is:

@ParseClassName("Posts")
public class VevantoParse extends ParseObject {

public static ParseQuery<VevantoParse> getQuery() {
    return ParseQuery.getQuery(VevantoParse.class);
}
}

I don't understand one thing: the "location" key. How does Parse know how to associate that key with my class in the cloud? In all the examples I've read, "location" is used as a key, but I don't understand the logic. Is there something that I have to set in the Parse dashboard? Each place in my database has a latitude and longitude. They were String at first; I changed them to Double, but it still didn't work.

I have also tried using a query that does not depend on my VevantoParse class:

ParseQuery<ParseObject> getPlacesQuery =            ParseQuery.getQuery("my_class_name");
ParseGeoPoint userLocation = new ParseGeoPoint(Double.valueOf("23.0465320"),    Double.valueOf("72.5925700"));
getPlacesQuery.whereWithinKilometers("location", userLocation,    MAX_SEARCH_DISTANCE);

But to no use. Note that the query works when I place conditions not related to location, like whereEqualTo. Can you shed some light on the problem, please? Any help would be greatly appreciated.

Regards, Narcis

Upvotes: 0

Views: 252

Answers (2)

Narcis
Narcis

Reputation: 236

For anybody interested, the problem is that I didn't define a Parse Geo Point in my server database. To do this, when you add a row into the database (I did it from my Java code), you simply define a Parse Geo Point named using a key ("location" in my case), and then you add the condition mapQuery.whereWithinKilometers("location", userLocation, MAX_SEARCH_DISTANCE); using that certain key.

Good luck!

Upvotes: 0

shkschneider
shkschneider

Reputation: 18253

To my knowledge you should pass the class name (as String) to the ParseQuery:

public static ParseQuery<VevantoParse> getQuery() {
    return ParseQuery.getQuery("VevantoParse"); // where VevantoParse is your Parse's class name
}

Here is the documentation.

Upvotes: 0

Related Questions