Reputation: 27
i want to get those points from database which are at some specified distance like within 2km from the given point. for this i use the following query in 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;
}
in this query LATITUDE and LONGITITUDE are columns of LOCATION_TABLE.
this query gives correct result in mysql but here it give this error
android.database.sqlite.SQLiteException: near "("
i didnt get where is problem in the query. Plz help.
Upvotes: 1
Views: 781
Reputation: 10346
If you're in Android, I suggest using the Location class's distanceTo() method. I wouldn't request the DB to perform this operation
More info here.
Upvotes: 2