查找附近的地点使用SQLite和Android [英] Find near locations with SQLite and Android
问题描述
我在约经度,纬度和描述信息SQLite数据库的数据表。考虑到一定的位置,我想获得的所有与该位置近距离(10块)的行。
I have a data table in my SQLite database with information about longitude, latitude and description. Given a certain location, I would like to get all the rows with a near distance (10 blocks) from that location.
这是数据是如何加载:
values.put(LONGITUD_COLUMN, (int) (-64.14802 * 1E6));
values.put(LATITUD_COLUMN, (int) (-31.36498 * 1E6));
到目前为止,这是我在code:
So far this is what I have in code:
private int cuadras = (int)(-0.02 * 1E6) ; //10 blocks aprox, I guess
private int current_latitude = 0;
private int current_longitude = 0;
current_latitude和current_longitude,都含有(从LocationListener的):
current_latitude and current_longitude, are loaded with (from LocationListener):
public void onLocationChanged(Location location) {
current_latitude = (int) (location.getLatitude() * 1E6);
current_longitude = (int) (location.getLongitude() * 1E6);
}
和SQLite的查询是如下:
And the SQLite query is as follows:
String sql = "LATITUD_COLUMN > (" + (current_latitude + cuadras) + ") AND "
+ "LATITUD_COLUMN < (" + (current_latitude - cuadras) +") AND "
+ "LONGITUD_COLUMN > ("+ (current_longitude - cuadras) +") AND "
+ "LONGITUD_COLUMN < ("+ (current_longitude + cuadras) +")";
通过这样的结果:
LATITUD_COLUMN > (-31398170) AND LATITUD_COLUMN < (-31358170) AND LONGITUD_COLUMN > (-64132838) AND LONGITUD_COLUMN < (-64172838)
该查询返回任何结果,我的问题是,我怎么能查询数据库把所有的位置靠近我当前的位置?
That query returns no results at all, my question is, how can I query the DataBase bringing all the locations near my current location?
谢谢!
推荐答案
您似乎有你的+和 - 混合起来:
You appear to have your + and - mixed up:
String sql = "LATITUD_COLUMN > (" + (current_latitude + cuadras) + ") AND "
+ "LATITUD_COLUMN < (" + (current_latitude - cuadras) +") AND "
+ "LONGITUD_COLUMN > ("+ (current_longitude - cuadras) +") AND "
+ "LONGITUD_COLUMN < ("+ (current_longitude + cuadras) +")";
应
String sql = "LATITUD_COLUMN > (" + (current_latitude + cuadras) + ") AND "
+ "LATITUD_COLUMN < (" + (current_latitude - cuadras) +") AND "
+ "LONGITUD_COLUMN > ("+ (current_longitude + cuadras) +") AND "
+ "LONGITUD_COLUMN < ("+ (current_longitude - cuadras) +")";
请注意调换的+和 - 在最后两行
Note the swapped + and - in the last two lines.
LONGITUD_COLUMN&GT; (-64132838)和LONGITUD_COLUMN&LT; (-64172838)
始终为false。 : - )
LONGITUD_COLUMN > (-64132838) AND LONGITUD_COLUMN < (-64172838)
is always false. :-)
这篇关于查找附近的地点使用SQLite和Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!