本文介绍了如何使用objectify-appengine在数据库中找到最近的点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我在我的应用程序中使用了objectify-appengine。在DB中,我存储了纬度&地方的经度。 在某些时候,我想找到最接近的地方(从数据库)到特定点。 据我所知,我不能执行常规的类似SQL的查询。 所以我的问题是如何以最好的方式完成?I'm using objectify-appengine in my app. In the DB I store latitude & longitude of places.at some point I'd like to find the closest place (from the DB) to a specific point.As far as i understood i can't perform regular SQL-like queries.So my question is how can it be done in the best way?推荐答案你应该看看 GeoModel ,它可以使用Google App Engine启用地理空间查询。You should take a look at GeoModel, which enables Geospatial Queries with Google App Engine. 更新:假设您在Objectify注释模型类中有一个GeoPt属性,名为 coordinates 。Let's assume that you have in your Objectify annotated model class, a GeoPt property called coordinates.您需要在您的项目中拥有两个库:You need to have in your project two libraries: GeoLocation.java Java GeoModelGeoLocation.javaJava GeoModel在您想要执行地理查询的代码中,您有以下内容:In the code that you want to perform a geo query, you have the following:import com.beoui.geocell.GeocellManager;import com.beoui.geocell.model.BoundingBox;import you.package.path.GeoLocation;// other imports// in your methodGeoLocation specificPointLocation = GeoLocation.fromDegrees(specificPoint.latitude, specificPoint.longitude);GeoLocation[] bc = specificPointLocation.boundingCoordinates(radius);// Transform this to a bounding boxBoundingBox 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 instanceList <String> modelCells = GeocellManager.generateGeoCell(myInstance.getCoordinate);// matchingfor (String c : cells) { if (modelCells.contains(c)) { // success, do sth with it break; }} 这篇关于如何使用objectify-appengine在数据库中找到最近的点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
09-05 01:22
查看更多