1

I'm trying to show images based on location in android, it seems sqlite doesn't support Math functions, i have no idea what should i do, i have just 1 day to meet the dead line and no way to use NDK to define functions because i have no idea what the NDK is, for some reasons i had to move the query from Mysql server to android sqlite here is my query. any help will be appreciated.

select id, 3956*2*asin(sqrt(power(SIN((" + latitude + "-latitude)*pi()/180/2),2) +" +
                "cos(" + latitude + "*pi()/180)* cos(latitude *pi()/180) * power(sin((" + longitude + " - longitude)*pi()/180/2),2))) as distance from " + LOCATIONS_TABLE_NAME + " limit 1 
Basil Battikhi
  • 2,638
  • 1
  • 18
  • 34
  • Is this a public, production-ready app or just some "demo" / internal use one? – Gergely Kőrössy Sep 04 '17 at 22:47
  • 1
    Select id, longitude and latitude and then do the calculations in java. – Aleksandar Varicak Sep 04 '17 at 22:49
  • @gegely, app is already in use – Basil Battikhi Sep 04 '17 at 23:06
  • @pernss, it seems that is the best way i dont know why i didn't think about this way, thank you , i notice that mysqlite is just a prank! Lol – Basil Battikhi Sep 04 '17 at 23:10
  • By the way I think there's a way to add custom functions to the SQLite database from the Java side without NDK, but it requires pretty heavy reflection usage and calling internal APIs, so it's better to stick with the clean Java approach instead as @PerunSS said. – Gergely Kőrössy Sep 04 '17 at 23:12
  • @geregely, yes i thought so , i just started implementing this query by java – Basil Battikhi Sep 04 '17 at 23:14
  • Not sure if any use [Contributed Files](https://www.sqlite.org/contrib). The last one is *Provide mathematical and string extension functions for SQL queries using the loadable extensions mechanism. Math: acos, asin, atan, atn2, atan2, acosh, asinh, atanh, difference, degrees, radians, cos, sin, tan, cot, cosh, sinh, tanh, coth, exp, log, log10, power, sign, sqrt, square, ceil, floor, pi. String: replicate, charindex, leftstr, rightstr, ltrim, rtrim, trim, replace, reverse, proper, padl, padr, padc, strfilter. Aggregate: stdev, variance, mode, median, lower_quartile, upper_quartile.* – MikeT Sep 05 '17 at 02:10
  • sounds cool i have to see it – Basil Battikhi Sep 05 '17 at 07:20

0 Answers0