Ok, I have a database with many location records there (storing latitude & longitude).
When new potential record comes, I need to check - if it is closer than 50 meters to any of existing records - I should not include it in database.
I know there is a possibility to calculate distance between two locations.
But in order to do that I need extract all records from my database and then in loop compare potential record to every existing. I suppose it will take some time.
I would like to have some delta, on which I can increase/decrease latitude & longitude of potential record - and that delta would give me 50 meters distance radius.
For example, I'd like to have something like that:
public boolean needsToBeIncluded(double newLat, double newLng) {
int delta = 0;
Cursor c = sqLiteDatabase.rawQuery("SELECT * FROM myLocations WHERE latitude between " + (newLat - delta) + " and " + (newLat + delta) +
" AND longitude between " + (newLng - delta) + " and " + (newLng + delta), null);
return c.getCount() > 0;
}
Is it possible or I have wrong imagination about latitude & longitude? Thx.