Nitish Patel
Nitish Patel

Reputation: 1026

How to create a user defined function in sqlite or get distance between 2 geopints?

I want to calculate distance between two geopoints one point which is stored in my local db and other point is my current location.How can I get it.

I want to fire

SELECT *, 3956 * 2 * ASIN ( SQRT ( POWER ( SIN((@orig_lat - abs(dest.lat)) * pi()/180   / 2), 2) +  COS(@orig_lat * pi()/180 )
* COS(abs(dest.lat) * pi()/180) *  POWER(SIN((@orig_lon – dest.lon) * pi()/180 / 2), 2) 
)) as  distance FROM hotels dest having distance < @dist ORDER BY distance limit 10;

this query in sqlite,but as I read on sqlite and stackoveflow that Sqlite doesn't support math functions.

So anyone know how to create user define function for this query in sqlite using C library and android NDK? or have another way to find it out ?

Upvotes: 0

Views: 880

Answers (1)

Doug Currie
Doug Currie

Reputation: 41200

The SpatiaLite functions are overkill, but certainly do what you need.

SpatiaLite is an open source library intended to extend the SQLite core to support fully fledged Spatial SQL capabilities.

There is an Android version.

Upvotes: 2

Related Questions