Querying Geopt with Objectify

别说谁变了你拦得住时间么 提交于 2020-01-13 19:21:08

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/31920968/querying-geopt-with-objectify

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!