This question already has an answer here:
I have store data in my SQLite that containing latitude and longitude some places, now I tried to find nearby place or location around user. I have tried to follow this solution but I still not get result.
this is how data load in table :
values.put("LATITUDE" , LATITUDE ); -->Text
values.put("LONGITUDE" , LONGITUDE ); -->Text
this is the way I tried to get list of nearby location :
public List<ModelProviderTerdekat> getProvider(Double LATITUDE, Double LONGITUDE) {
List<ModelProviderTerdekat> list = new ArrayList<ModelProviderTerdekat>();
SQLiteDatabase db = this.getReadableDatabase();
int cuadras = (int)(-0.02 * 1E6) ;
int current_latitude = (int) (LATITUDE * 1E6);
int current_longitude = (int)(LONGITUDE * 1E6);
Cursor cursor = db
.rawQuery(
"SELECT a.LSKA_NOTE, a.RSALAMAT, a.RSTELEPON, a.RSNAMA, a.LATITUDE, a.LONGITUDE," +
" case when b.FLAG_FAV is not null then 1 else 0 end as FLAG_FAV," +
" a.RSTYPE, a.RSID, a.RS_NTT FROM LST_PROVIDER a left join LST_PROVIDER_FAV b " +
"on a.RSID = b.RSID where LATITUDE > (" + (current_latitude + cuadras) +") AND "
+ "LATITUDE < (" + (current_latitude - cuadras) +") AND "
+ "LONGITUDE > ("+ (current_longitude + cuadras) +") AND "
+ "LONGITUDE < ("+ (current_longitude - cuadras) +")",
null);
if (cursor.moveToFirst()) {
do {
list.add(new ModelProviderTerdekat(cursor.getString(0), cursor.getString(1),cursor.getString(2),
cursor.getString(3), cursor.getString(4),cursor.getString(5), cursor.getInt(6),
cursor.getInt(7), cursor.getInt(8), cursor.getInt(9)));
} while (cursor.moveToNext());
}
return list;
}
the query will be like this :
SELECT a.LSKA_NOTE, a.RSALAMAT, a.RSTELEPON, a.RSNAMA, a.LATITUDE, a.LONGITUDE, case when b.FLAG_FAV is not null then 1 else 0 end as FLAG_FAV, a.RSTYPE, a.RSID, a.RS_NTT FROM LST_PROVIDER a left join LST_PROVIDER_FAV b on a.RSID = b.RSID where LATITUDE > (-6157749) AND LATITUDE < (-6117749) AND LONGITUDE > (106802334) AND LONGITUDE < (106842334)
how can I query the Database for bringing all the locations near my current location?
Aucun commentaire:
Enregistrer un commentaire