So I'm writing an Android app and want to write a SQLite query such that it selects only rows that contain event location info utilizing a distance constraint in miles and current longitude and latitude and ordering by that calculated distance. Eventually once I've gotten further along the SQLite database will instead make this query on a database on Azure which may or may not open up some functionality, rather than querying a SQLite database that's inserted with mock data. But since I'm working with SQLite ATM I'm trying to come up with a Android-SQLite solution.
The SQLite table schema is such:
event_id | event_name | event_latitude | event_longitude
Below is some pseudocode mixed with real code to get an idea of what I'm trying to create:
sqlite_table = "some_table";
double distanceConstraint = 50.00; //in miles
//using Decimal Degrees (DDD) as it's probably easiest to calculate with
currentLat = 41.40338;
currentLong = 2.17403;
mCursor = mDb.query(true,
SQLITE_TABLE,
new String[] {event_id, event_name},
/* (where) current lat & long is within distanceContraint of event_latitude & event_longitude*/,
null,
null,
null,
/* distanceBetweenPointsResult */ + " DESC",
null);
How do I write the query to calculate the distance (in miles) between current location and the event's and filter and order accordingly?