我有一个应用程序,可以在用户开车时为他们显示最近的加油站。现在我可以显示最近的前10个加油站。我还想构建的是显示一个视图,显示用户当前位置和最近的加油站之间的距离,我从数据库中收集的前10名,即第一个。我是怎么想的
1- The GPS provide a new location to my application.
2- run an SQL query to get the top 10 gas stations in a Circle that it center is the user location and it radius is 2 km.
3- calculate the distance between the current location and the first gas station returned from the Query above (which is the nearest one) .
4- display that distance to user.现在为什么我不认为这是不好的,因为gps供应商可能会晚提供一个新的位置,因为我将它们过滤到200米精度内。并且我执行I/O操作,这可能需要很长时间才能返回。所有这些都将导致用户与最近的加油站之间的固定距离,并等待更新。
请注意以下事项
1-我为我在查询中使用的列建立索引,以加快速度并防止完全扫描问题。
2-这就是我如何定义我的更新请求,以尽快获得位置更新。this.mLocationManager.requestLocationUpdates("gps", 0, 0, this.mLocationListener);
有没有更快的方法来做到这一点?
发布于 2012-12-11 04:13:59
有些方法的速度要快1000倍。为什么是一个可怕的慢sql?在嵌入式系统中,sql不是最佳选择。读取内存中的所有加油站(数组)。至少是坐标和站点id。
一个简单的解决方案:进行暴力搜索并计算所有距离,当您找到最近的站点时,保留最近的站点,然后您可以在sql中查询地址、名称等。
如果你有超过10.000个工作站,你可能需要一个更好的解决方案。
发布于 2012-12-11 04:28:26
如果你想使用一些数据库,我会推荐mongoDB - no SQL数据库。它有带"near“功能的GeoIndex。
这可以获得非常高的读取性能,并且您不需要发明轮子。
请参阅http://www.mongodb.org/display/DOCS/Geospatial+Indexing
https://stackoverflow.com/questions/13808232
复制相似问题