I have developed a this function for search all element in a 20 km range respect position of single element into
ArrayList<GeoJsonResponse> result = new ArrayList<GeoJsonResponse>();
Cursor cursor = mDb.query(database_event_schema.TABLE_NAME, null, null, null, null, null, null);
String[] colums = new String[]{database_event_schema._EVENT_ID,database_event_schema._AUTHOR, database_event_schema._LAT,database_event_schema._LON,database_event_schema._PLACE,database_event_schema._MAG,database_event_schema._DEPTH,database_event_schema._TIME};
Double lat,lon,magnitude = null,distance = null;
if (cursor != null) {
while (cursor.moveToNext()) {
try{lat = Double.valueOf(cursor.getString(cursor.getColumnIndex(database_event_schema._LAT)));}catch(Exception e){continue;}
try{lon = Double.valueOf(cursor.getString(cursor.getColumnIndex(database_event_schema._LON)));}catch(Exception e){continue;}
String place = cursor.getString(cursor.getColumnIndex(database_event_schema._PLACE));
double dist_km = Utills.distance(curPos.latitude,curPos.longitude,lat,lon,'K');
if(dist_km>=0 && dist_km<=10) {
String id = cursor.getString(cursor.getColumnIndex(database_event_schema._EVENT_ID));
String author = cursor.getString(cursor.getColumnIndex(database_event_schema._AUTHOR));
try{magnitude = Double.valueOf(cursor.getString(cursor.getColumnIndex(database_event_schema._MAG)));}catch(Exception e){}
try{distance = Double.valueOf(cursor.getString(cursor.getColumnIndex(database_event_schema._DEPTH)));}catch(Exception e){}
String date = cursor.getString(cursor.getColumnIndex(database_event_schema._TIME));
Date dateNew = null;
if(!date.equals(""))
{
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
try {
dateNew = format.parse(date);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Log.e("test", e.getLocalizedMessage());
}
}
result.add(new GeoJsonResponse(id,author,place,magnitude,distance,date,dateNew,lat,lon));
}
}
}
return result;
but the query is very slow. How can I increase the speed query? I have write a wrong code?
Thanks
Aucun commentaire:
Enregistrer un commentaire