RCB*_*RCB 2 google-app-engine persistence objectify
我在我的应用程序中使用了objectify-appengine.在DB我存储纬度和经度的地方.在某些时候,我想找到最接近的地方(从数据库)到特定点.
据我所知,我无法执行常规的类似SQL的查询.所以我的问题是如何以最好的方式完成?
您应该看一下GeoModel,它可以使用Google App Engine启用地理空间查询.
更新:
假设您在Objectify注释模型类中有一个名为GeoPt的属性coordinates.
你需要在你的项目中有两个库:
在要执行地理查询的代码中,您具有以下内容:
import com.beoui.geocell.GeocellManager;
import com.beoui.geocell.model.BoundingBox;
import you.package.path.GeoLocation;
// other imports
// in your method
GeoLocation specificPointLocation = GeoLocation.fromDegrees(specificPoint.latitude, specificPoint.longitude);
GeoLocation[] bc = specificPointLocation.boundingCoordinates(radius);
// Transform this to a bounding box
BoundingBox bb = new BoundingBox((float) bc[0].getLatitudeInDegrees(),
(float) bc[1].getLongitudeInDegrees(),
(float) bc[1].getLatitudeInDegrees(),
(float) bc[0].getLongitudeInDegrees());
// Calculate the geocells list to be used in the queries (optimize
// list of cells that complete the given bounding box)
List<String> cells = GeocellManager.bestBboxSearchCells(bb, null);
// calculate geocells of your model class instance
List <String> modelCells = GeocellManager.generateGeoCell(myInstance.getCoordinate);
// matching
for (String c : cells) {
if (modelCells.contains(c)) {
// success, do sth with it
break;
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
927 次 |
| 最近记录: |