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?
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.