Querying Geopt with Objectify

匆匆过客 提交于 2019-12-06 06:47:02
stickfigure

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

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