views:

876

answers:

1

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.

+1  A: 

from: http://www.zentus.com/sqlitejdbc/api/org/sqlite/Function.html

A subclass of org.sqlite.Function can be registered with Function.create() and called by the name it was given. All functions must implement xFunc(), which is called when SQLite runs the custom function.

You could use the above to create a content provider (http://developer.android.com/guide/topics/providers/content-providers.html) that did what you wanted. Or, you could just create a view of the data that performed the law-of-cosines + calc in sql and work with that.

Joshua Smith
Josh,Thank you! If you don't mind, could you please point me to some sample code - I would then be sure not to make a mistake. Thanks a ton!
Puneet
org.sqlite is not an Android API, so that is not relevant.
hackbod
You are correct, org.sqlite is not an Android API. However, you can use it to implement a Content Provider that does what he asked.
Joshua Smith
Actually, I'm rather skeptical on the approach outlined in the content provider answer you link to. `org.sqlite` is not in Android, and it is unclear if there exists an `org.sqlite` implementation that will work in concert with Android's SQLite environment.
Pentium10