We are building an Android App that will use user\'s current location (lat, long) and show top 50 venues around the current location, sorted by distance.
We have the
I know this is an old question, but there is a little bit easier solution I think.
This is an example, but it fails when crossing 0 degrees, although you could shift all the latitude/longitudes to adjust.
The overall solution works pretty well for ordering, but just uses the Pythagorean theorem to calculate the relative distance (note: no square root function in sqlite, but that is not relevant).
String calcDistance = "( ( (abs(" + cLat + ") - " + Math.abs(lat) + ") * (abs(" + cLat + ") - " + Math.abs(lat) + ") )" +
"+ ( (abs(" + cLng + ") - " + Math.abs(lng) + ") * (abs(" + cLng + ") - " + Math.abs(lng) + ") ) ) as calc_distance";
If you needed to fix this distance, you would want to adjust by adding 90 to all latitudes and 180 to all longitude. Then you could get rid of that nasty abs functions.