找到多个点之间的距离

时间:2013-01-24 18:06:47

标签: android sqlite

我希望从数据库中获取这些点,这些点距离给定点在2km范围内。为此我在sqllite中使用以下查询,

    public Cursor GetLoc(int lat, int longi, int dist)
    {   
        Cursor c = db.rawQuery("SELECT *, ((Math.acos(Math.sin("+ lat +"* PI() / 180) * Math.sin("+ LATITUDE +"* PI() / 180) + Math.cos("+ lat +"* PI() / 180) * Math.cos("+LATITUDE+"* PI() / 180) * Math.cos(("+ longi +" - "+LONGITITUDE+") * PI() / 180)) * 180 / PI()) * 60 * 1.1515 * 1.609344) AS distance FROM " + LOCATION_TABLE +" WHERE distance = " + dist, null);
        return c;
    }

在此查询中,LATITUDE和LONGITITUDE是LOCATION_TABLE的列。

这个查询在mysql中给出了正确的结果但是在这里它给出了这个错误

 android.database.sqlite.SQLiteException: near "("

我没有得到查询中的问题。 Plz帮助。

1 个答案:

答案 0 :(得分:2)

如果你在Android中,我建议使用Location类的distanceTo()方法。我不会要求DB执行此操作

更多信息here