用Objectify查询Geopt

我最难用Objectify查询GeoPt字段。

我确定有关于GeoPt字段的@Index注释。

但是,以下声明似乎不起作用

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

在Objectify中查询GeoPt字段是否可行?

数据存储区不支持以这种方式查询GeoPt 。 如果您想查询纬度,请单独索引(可能在@OnSave方法中写入私有字段)。 但是,如果您尝试执行地理空间查询(即包含在矩形中),请注意您不能执行两个不等式filter(边界中的纬度,边界中的经度)。

好消息是,谷歌最近添加了直接向数据存储区执行地理空间查询的function:

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); 

请注意,数据存储的地理空间搜索目前是Alpha版本,对于邀请而言是关闭的。 因此,虽然您可以让地理空间搜索在本地工作,但它仍然无法用于生产。 请参阅: Google App Engine> GeoSpatial Alpha Invite

Interesting Posts