Hello, I don't know if I'm wierd, but I haven't found any topic about the subject. The thing is, I have data with lat and lng 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).
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 nothing yet, that is written in Java and is functioning.
Also, if I want to add custom functions, I need the org.sqlite .jar (for org.sqlite.Function) and that adds unnecessary size to the app.
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 DB. That would mean updating the DB everytime 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!
I know there are tons of Android apps out there that use this function, but can someone please explain the magic :)
Thanks!
Btw: found this alternative: http://stackoverflow.com/questions/3126830/query-to-get-records-based-on-radius-in-sqlite
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?