用物化看问题 [英] Querying Geopt with Objectify

查看:102
本文介绍了用物化看问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



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



然而,下面的语句似乎并不奏效$ / b>

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

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

GeoPt 。如果您希望在纬度上进行查询,请单独编制索引(可能会在@OnSave方法中写入专用字段)。但是,如果您尝试执行地理空间查询(即,包含在矩形中),请注意您不能执行两个不等式过滤器(边界内的纬度,边界内的经度)。

好消息是,最近google增加了直接对数据存储区执行地理空间查询的功能: google.com/appengine/docs/java/datastore/geosearchrel =nofollow> 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邀请


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?

解决方案

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

这篇关于用物化看问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆