Johnny Wu
Johnny Wu

Reputation: 1518

Querying Geopt with Objectify

I am having the hardest time querying a GeoPt field with Objectify.

I made sure there's an @Index annotation about the GeoPt field.

However, the statement below doesn't seem to work

ofy().load()
     .type(GeoStat.class)
     .filter("geoPt.latitude >=", neLat)
     .limit(10);

Is querying GeoPt field possible in Objectify?

Upvotes: 2

Views: 1238

Answers (1)

stickfigure
stickfigure

Reputation: 13556

The datastore does not support querying a GeoPt in this way. If you wish to query on latitude, index it separately (possibly writing to a private field in an @OnSave method). However, if you're trying to perform a geospatial query (ie, contained in a rectangle), note that you cannot perform two inequality filters (latitude in bounds, longitude in bounds).

The good news is that very recently google added the ability to perform geospatial queries directly to the datastore:

https://cloud.google.com/appengine/docs/java/datastore/geosearch

GeoPt center = new GeoPt(latitude, longitude);
double radius = valueInMeters;
Filter f = new StContainsFilter("geoPt", new Circle(center, radius));
ofy().load().type(GeoStat.class).filter(f);

Note, that geospatial search for datastore is currently an Alpha release, that is closed for invitations. So, while you can get the geospatial search to work locally, it still cannot be used in production. See: Google App Engine › GeoSpatial Alpha Invite

Upvotes: 5

Related Questions