i have sqlite tablewith five columns (rownum,nodeid,lat,lng,max). and some lat points are repeated in the table, for an example
1,21211,34.21212,8.11289,90
2,21311,34.94674,8.xx,90
3,215611,34.9934,8.xx,20
4,24311,34.121335673,8.xx,40
5,22211,34.009473,8.xx,60
6,21265,34.21212,8.9786750,70
7,21261,34.21212,8.9786754,80
as you see the latitude value is repeated in the 1st,6th and the 7th rows, and what i want to do is, to make the query return the longitude value of the latitude i am searching for. for an example, given the code posted below, when i call getLngs(34.21212) the query should return a list containing 8.11289,8.9786750 and 8.9786754
the code posted below returns only one value
code:
public ArrayList getLngs(String lat) {
ArrayList list = new ArrayList<String>();
SQLiteDatabase db = this.getReadableDatabase();
SQLiteCursor c = (SQLiteCursor) db.rawQuery("SELECT lng FROM " + DATABASE_TABLE_NAME + " WHERE lat = " + lat + " And lng IS NOT NULL", null);
c.moveToFirst();
if (c.getCount() == 0) {
return null;
} else {
while (c.moveToNext()) {
list.add(c.getString(c.getColumnIndexOrThrow("lng")));
}
}
c.close();
db.close();
return list;
}
try this maybe it will work-
public ArrayList getLngs(String lat) {
ArrayList list = new ArrayList<String>();
SQLiteDatabase db = this.getReadableDatabase();
SQLiteCursor c = (SQLiteCursor) db.rawQuery("SELECT lng FROM " + DATABASE_TABLE_NAME + " WHERE lat = " + lat + " And lng IS NOT NULL", null);
if (c.moveToFirst()) {
do {
list.add(c.getString(c.getColumnIndexOrThrow("lng")));
} while (c.moveToNext());
}
c.close();
db.close();
return list;
}