Formulas to Calculate Geo Proximity
(I am new in android development so please suggest me the best answer don't vote for downcast, and sorry for my bad english)
I am Using Haver Sine formula to calculate distance bt 2 points.
In above case Alix Axel uses mysql and php, but in my case i am implmenting this on my android app, actually in my app i have a LocationService (background) in which my app will continuesly fatch lon/lat using both GPS and Network provider using....
locationManager.requestLocationUpdates(provider, THIRTY_SEC, HUNDRED_METER, Locationlistener);
once a best is found than on the basic of that location i am performing sqlite indexng query, my sqlite query is (this method is synchronized in SQLiteHelper class)
SELECT * FROM (
SELECT * FROM Places WHERE
(Lat >= 1.2393 AND Lat <= 1.5532) AND (Lon >= -1.8184 AND Lon <= 0.4221)
) WHERE
acos(sin(1.3963) * sin(Lat) + cos(1.3963) * cos(Lat) * cos(Lon - (-0.6981))) <= 0.1570;
as above this query results some rows which i am storing in local variable
List<Places> places = aboveQuery(location);
resultant places may be 1,100 or more, after that i am generating a simple notifications for each places in list. so notification still may be 1, 100 or more. Below is my code where i am performing this task.
public class LocationServices extends Service {
// rest of the code here to fatch location using GPS, Network
private class LocationServiceProcess implements Runnable {
@Override
public void run() {
try {
List<Places> Places = query a databse for location matching
// generate notification here
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
}
i think now you guys can understand my problem, now my questions are
as Alix Axel said in his post that The Haversine Formula is way faster than the Vincenty Formula, I was able to run 1 million calculations in about 6 seconds which is pretty much acceptable for my needs
Is this scnario is best to fetch places on the behalf of current location from database (supose in my database table contains thousends of places/rows). i.e this calculation and quering a data in service thread is best or not. (should i perform on another than Service main thread) if not than tell me what to do??
After that once i have a list of places than, is it best idea to generate notifications in the same thread or brodcast all places and than in BroadCastReceiver generate notification for each places. Keep in mind just simple notifications, which contains only Name of places, Time to occur, and small description