在SQLite中比较Double NOT字符串值

时间:2013-04-24 21:15:34

标签: android sqlite comparison

我正在尝试使用BETWEEN运算符通过Android比较sqlite中的纬度和经度值。问题是,值总是被比较为它是一个字符串,我无法弄清楚如何将它作为一个数字进行比较。我发现了这一点,因为使用查询“select * from database orderby latitude”会返回一个未按数字顺序排列的列表。 KEY_LAT和KEY_LONG我已经存储了TEXT和REAL,我得到了相同的输出。请告诉我你需要什么信息。

以下是查询:

         double high_lat = curr_lat + 100.0;
     double high_long = curr_longitude + 100.0;
     double low_lat = curr_lat - 100.0;
     double low_long = curr_longitude - 100.0;
         Cursor cursor = db.query(TABLE_NAME,      new String[]                        {KEY_ID, KEY_NAME, KEY_ADDR, KEY_LAT, KEY_LONG}, select,
        new String[]
                {KEY_LAT + " BETWEEN " + low_lat + " AND " 
                + high_lat + " AND " + KEY_LONG + " BETWEEN " + low_long + " AND " 
                + high_long},
            null, null, null);

1 个答案:

答案 0 :(得分:1)

将您的输入转换为REAL作为最后的方法。

...KEY_LONG + " BETWEEN CAST(" + low_long + " AS REAL) AND CAST(" + high_long +" AS REAL)"