This is the method that I have been using to get a sort clause for objects with GPS data stored in a database:
public String getOrderString(double latitude, double longitude) {
double fudge = Math.pow(Math.cos(Math.toRadians(latitude)), 2);
return "((" + latitude + " - " + KEY_LATITUDE + ") * (" + latitude
+ " - " + KEY_LATITUDE + ") + (" + longitude + " - "
+ KEY_LONGITUDE + ") * (" + longitude + " - " + KEY_LONGITUDE
+ ") * " + fudge + ") ASC";
}
'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:
public String getWhereString(double latitude, double longitude, double threshold) {
double fudge = Math.pow(Math.cos(Math.toRadians(latitude)), 2);
return "((" + latitude + " - " + KEY_LATITUDE + ") * (" + latitude
+ " - " + KEY_LATITUDE + ") + (" + longitude + " - "
+ KEY_LONGITUDE + ") * (" + longitude + " - " + KEY_LONGITUDE
+ ") * " + fudge + ") < " + threshold;
}
Then your delete method would be like:
public int removeBuildingEntry(double latitude, double longitude, double threshold) {
String where = getWhereString(double latitude, double longitude, double threshold)
return db.delete(TABLE, where, null);
}
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.