根据当前位置删除数据库行
我将具有位置(纬度/经度)的对象存储在我的 Android 应用程序的普通 SQLite 数据库中。应用程序接收带有存储在该数据库中的新对象的消息(UDP 数据包)。
为了避免数据库在某一时刻爆炸并保持轻便,我想永久删除所有距离超过特定半径的对象。 DB 通过实现 DB Helper 的 DB-Adapter 类进行控制。
由于我不想使用距离近似,因此我想使用半正矢公式。现在我有以下问题:
- 在轻量级智能解决方案中实现此任务的最佳方式是什么?
- 我考虑过使用 AsyncTask 来完成这项工作。这是推荐的吗?
I store objects with a position (lat/long) in a normal SQLite database in my Android applicaton. The application receives messages (UDP packets) with new objects which are stored in the this DB.
To avoid the explosion of the DB at one point and to keep it light, I would like to delete all objects which are further away than a specific radius permanently. The DB is controlled via a DB-Adapter class implementing a DB Helper.
As I do not want to use distance approximations, I would like to use the haversine formula. Now I have the following questions:
- What is the best way to implement this task in a lightweight intelligent solution?
- I thought about using an AsyncTask to do the job. Is this recommended?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是我一直用来获取数据库中存储的 GPS 数据的对象的排序子句的方法:
从 此处。我对模糊因子的理解是,它考虑了不在赤道附近的坐标。到目前为止,这个方程对我来说效果很好,而且速度相当快。
现在,我认为您可以通过执行以下操作来利用相同的方程:
那么您的删除方法将类似于:
唯一的问题是我不知道方程结果的单位,因此您应该传递什么一个门槛。在我的情况下,我不关心这些,因为我只想要订单,但在你的情况下,这可能会有所不同。您可以尝试使用不同的值,或者如果您需要更准确的数字,则尝试计算它。
This is the method that I have been using to get a sort clause for objects with GPS data stored in a database:
'borrowed' from here. My understanding of the fudge factor is that it takes into account coordinates that are not near the equator. This equation has worked well for me so far and is fairly quick.
Now, I think you can utilize the same equation, by doing something like:
Then your delete method would be like:
The only issue is that I do not know the units of the result of the equation, and therefore what you should pass in as a threshold. In my situation I don't care about those as I only want the order, but in your case that might make a difference. You could either play around with different values or attempt to calculate it if you need a more exact number.