Reputation: 3515
I am trying to catch values from the database in to a array list. and i want to get only the latitude and the longitude to create the markers.
here is my gettemple() function in db handler class
public ArrayList<kovil> Get_Temple(String temple_type, String Limit) {
try {
temple_list.clear();
// Select All Query
String selectQuery = "SELECT * FROM " + TABLE_TEMPLE +"WHERE KEY_TMPTYPE=" + temple_type +"LIMIT" + Limit;
SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.rawQuery(selectQuery, null);
System.out.print("CALLED");
// looping through all rows and adding to list
if (cursor.moveToFirst()) {
do {
kovil Kovil = new kovil();
Kovil.setID(Integer.parseInt(cursor.getString(0)));
Kovil.settemplename(cursor.getString(1));
Kovil.settempletype(cursor.getString(2));
Kovil.setlatitude(cursor.getString(3));
Kovil.setlongitude(cursor.getString(4));
Kovil.setimage_name(cursor.getString(5));
Kovil.setyear_build(cursor.getString(6));
Kovil.setaddress(cursor.getString(7));
Kovil.setcity(cursor.getString(8));
Kovil.setemail(cursor.getString(9));
Kovil.setwebsite(cursor.getString(10));
Kovil.settelephone1(cursor.getString(11));
Kovil.settelephone2(cursor.getString(12));
Kovil.setDescription(cursor.getString(13));
// Adding contact to list
temple_list.add(Kovil);
} while (cursor.moveToNext());
}
// return contact list
cursor.close();
db.close();
return temple_list;
} catch (Exception e) {
// TODO: handle exception
Log.e("all_temples", "" + e);
}
return temple_list;
}
this will return the temple_list array in the same class.
private final ArrayList<kovil> temple_list = new ArrayList<kovil>();
and trying to call the Get_Temple() function in view map class
dbhand.Get_Temple((getIntent().getExtras().getString("temple_type")), getIntent().getExtras().getString("notemples"));
for (int i=0; i< Integer.parseInt(getIntent().getExtras().getString("notemples"));i++) {
//displaytemples(9.662502, 80.010239, "mugan kovil");
}
and i am trying to display the markers using this class
public boolean displaytemples(double lati, double longi, String templename){
MarkerOptions marker = new MarkerOptions().position(new LatLng(lati, longi)).title(templename);
marker.icon(BitmapDescriptorFactory.fromResource(R.drawable.icon));
//marker.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_GREEN));
mMap.addMarker(marker);
return true;
}
I want to catch only the latitude and the longitude from the array list and using that for loop i want to pass the latitude and the longitude to the displaytemples ().
can any one help me to write the for loop which will catch only the latitude and the longitude and pass it to the displaytemples()
function. thank you...
Upvotes: 0
Views: 3424
Reputation: 20934
To be honest, your code makes me scared... But that's different problem. The only thing I would point out - is please do not fetch DB from the main thread. You are blocking UI this way :( . Look at AsyncTask
or some other ways to offload DB operations off the main thread..
As for your problem - you can try something like this:
ArrayList<kovil> data = dbhand.Get_Temple(getIntent().getExtras().getString("temple_type"),
getIntent().getExtras().getString("notemples"));
for (kovil temple: data) {
displaytemples(Double.parseDouble(temple.getlatitude(),
temple.getlongitude(),
temple.gettemplename());
}
Upvotes: 1