title: SQlite Getting nearest locations (with latitude and longitude)
body: <p>I have data with latitude and longitude stored in my SQLite database, and I want to get the nearest locations to the parameters I put in (ex. My current location - lat/lng, etc.).</p>
  
  <p>I know that this is possible in MySQL, and I've done quite some research that SQLite needs a custom external function for the Haversine formula (calculating distance on a sphere), but I haven't found anything that is written in Java and works.</p>
  
  <p>Also, if I want to add custom functions, I need the <code>org.sqlite</code> .jar (for <code>org.sqlite.Function</code>), and that adds unnecessary size to the app.</p>
  
  <p>The other side of this is, I need the Order by function from SQL, because displaying the distance alone isn't that much of a problem - I already did it in my custom SimpleCursorAdapter, but I can't sort the data, because I don't have the distance column in my database. That would mean updating the database every time the location changes and that's a waste of battery and performance. So if someone has any idea on sorting the cursor with a column that's not in the database, I'd be grateful too!</p>
  
  <p>I know there are tons of Android apps out there that use this function, but can someone please explain the magic.</p>
  
  <p>By the way, I found this alternative: <a href="https://stackoverflow.com/questions/3126830">Query to get records based on Radius in SQLite?</a></p>
  
  <p>It's suggesting to make 4 new columns for cos and sin values of lat and lng, but is there any other, not so redundant way?</p>