mercredi 1 avril 2015

Connection sqlite in android studio


Vote count:

0




Hye There,


My project to read latitute and longitute in sqlite database. First of all, i cant connect my connection to database sqlite. and second after connection succeed and i dont know how to loop all data in this google map.


Example one data in my database:


_id DateOc TimeOc Location Latitude Longitude


1 5-11-1961 4.30am Ringlet, Cameron Highlands,Pahang 4.415895 101.383082


Thanks In advance who helping me, I appreciate that, sincerely, Hafizul Reza



private GoogleMap mMap; // Might be null if Google Play services APK is not available.

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setContentView(R.layout.activity_maps);
setUpMapIfNeeded();
}

@Override
protected void onResume() {
super.onResume();
setUpMapIfNeeded();
}

private void setUpMapIfNeeded() {
// Do a null check to confirm that we have not already instantiated the map.
if (mMap == null) {
// Try to obtain the map from the SupportMapFragment.
mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map))
.getMap();
// Check if we were successful in obtaining the map.
if (mMap != null) {
setUpMap();
}
}
}


private void setUpMap() {

int i = 1;
if(i==1){
SQLiteDatabase myDB = null;
String TableName = "Landslide";

//String Data="";

myDB = this.openOrCreateDatabase("Landslide", MODE_PRIVATE, null);

Cursor c = myDB.rawQuery("SELECT * FROM " + TableName, null);

double Column1 = c.getColumnIndex("Latitude");
double Column2 = c.getColumnIndex("Longitude");
//int Column3 = c.getColumnIndex("Location");


mMap.addMarker(new MarkerOptions().position(new LatLng(Column1 , Column2)).title("Zasss"));
}

//Loop through all Results
//do {
//Data =Data +a+"|"+b+"\n";
// }while(c.moveToNext());
//}

//double lat = 4.415895;
//double lng = 101.383082;
else

//mMap.addMarker(new MarkerOptions().position(new LatLng(Column1, Column2)).title("Column3"));
mMap.addMarker(new MarkerOptions().position(new LatLng(3.37376388889, 101.615391667)).title("Kg. Sri Serendah"));
}
}


asked 35 secs ago







Connection sqlite in android studio

Aucun commentaire:

Enregistrer un commentaire