how to show locations on google map activity stored in sql database stored from an arraylist of locations . I am using geocoder class to get the longitude and latitude of the locations please help me to carry out the same process
Asked
Active
Viewed 1,232 times
1 Answers
1
I suppose you have an object class Location, it contains title, latitude, longitude. In your database it also have 3 columns Title, Latitude and Longitude.
Now in your database class extends SQLiteOpenHelper, you should have:
private SQLiteDatabase database;
Then use below method to get all locations into an arraylist, and you can do anything you want with that return list.
public ArrayList<Location> getLocationList() {
ArrayList<Location> locationList = new ArrayList<>();
String query = "SELECT * FROM Your_Table_Name";
Cursor cursor = database.rawQuery(query, null);
int ColumeLatitude = cursor.getColumnIndex("Latitude");
int ColumeLongitude = cursor.getColumnIndex("Longitude");
int ColumeTitle = cursor.getColumnIndex("Title");
while (cursor.moveToNext()) {
String title = cursor.getString(ColumeTitle);
String latitude = cursor.getString(ColumeLatitude);
String longitude = cursor.getString(ColumeLongitude);
Location location = new Location(title, latitude, longitude);
locationList.add(location);
}
cursor.close();
return locationList;
}
Hope it helps!

Dang Nguyen
- 354
- 2
- 9
-
sorry friend you are not understanding my problem i have the addresses of locations stored in my arraylist and then i made it stored in a database then how to show all that locations that i have stored int database hopefully now you would have understood my question please respond if have any answer related to my question – Lakshay Gupta Jul 28 '16 at 04:01
-
Thank You for trying but if i try to do by using geocder class as this class would not require any longitude and latitude of the location it only require the location address so if you any idea related to this please let me know – Lakshay Gupta Jul 28 '16 at 04:45
-
I have not used Geocoder class but I think this link maybe help you: http://stackoverflow.com/questions/15711499/get-latitude-and-longitude-with-geocoder-and-android-google-maps-api-v2 – Dang Nguyen Jul 28 '16 at 06:07