查询来获取SQLite中基于RADIUS记录? [英] Query to get records based on Radius in SQLite?
问题描述
我有这个疑问这确实做工精细MySQL中
I have this query which does work fine in MySQL
SELECT ((ACOS(SIN(12.345 * PI() / 180) * SIN(lat * PI() / 180) +
COS(12.345 * PI() / 180) * COS(lat * PI() / 180) * COS((67.89 - lon) *
PI() / 180)) * 180 / PI()) * 60 * 1.1515 * 1.609344) AS distance, poi.*
FROM poi
WHERE lang='eng'
HAVING distance<='30'
距离在公里,输入经纬度= 12.345
和 LON = 67.89
在SQLite是3,我不能用它运行自定义的功能,因为它是在Android上。我也没有ACOS()等等......因为这不是标准的SQLite的一部分。
The SQLite is 3, and I can't run custom functions with it as it's on Android. I also don't have acos() etc... as that is not part of the standard SQLite.
如何将上面的查询SQLite中?
How would be the above query in SQLite?
推荐答案
您可以创建4个新列,是罪和 COS纬度
和 LON
。由于 COS(A + B)= COS一个COS b - 罪过罪过b
,以及正弦和余弦的其他出现如 SIN(12.345 * PI ()/ 180)
运行查询之前,可以计算出程序,大大的距离EX pression减少了一些形式 P * SIN_LAT + Q * COS_LAT + ...
可通过sqlite3的处理。
You can create 4 new columns, being sin and cos of lat
and lon
. Since cos(a+b) = cos a cos b - sin a sin b
, and other appearances of sin and cos like SIN(12.345 * PI() / 180)
can be calculated in the program before running the query, the big "distance" expression reduces to something of the form P * SIN_LAT + Q * COS_LAT + ...
that can be handled by SQLite3.
顺便说一下,也见<一href="http://stackoverflow.com/questions/2352320/sqlite-on-android-how-to-create-a-sqlite-dist-db-function-to-be-used-in-the-ap">http://stackoverflow.com/questions/2352320/sqlite-on-android-how-to-create-a-sqlite-dist-db-function-to-be-used-in-the-ap.
这篇关于查询来获取SQLite中基于RADIUS记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!