Sqlite on Android: How to create a sqlite dist db function - to be used in the app for distance calculation using lat, long

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 these venues stored in an SQLite DB. We plan to ship with the sqlite DB with the app.

In order to fetch only the relevant top 50 closest venues, we want to define a db function DIST (to calculate distance between two points) and use it in our query.

How can I define a custom SQLite function for Android Apps? What will be the Java API call to do this?

We have successfully implemented this approach in our iPhone App - using Objective C.


Update: The answer is that you can not do this.

from: Android. Is it posible to write custom function on C/C++ and use it in SQL query?

A workaround might be to fetch all records where one of the values (say, longitude) is close to the current location. If you use this column as an index then fetching these will be very fast.

Then, you have a much reduced subset to iterate over comparing the latitudes and doing your full distance calculations.

It can be done but you cannot load this into the database from the Java API. You will need to provide your own implementation of the sqlite library that is extended to provide the functions you wish at the C level. This is not fun but it works well. Be aware that you may have issues with Android devices using non-standard architectures.

Need Your Help

How do we update an existing XML file in C#

c# xml

I have an existing xml file which I want to update.

Graphics2D.drawString very slow

java swing graphics2d

I'm using Java Graphics2D to draw some lines and labels into a JPanel. The drawing code is running extremely slowly (drawString() seems the worst, but I no longer think it is the culprit, just the

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.