Android sqlite cursor for map adapter

I have this section of code in my DataSource class to list the lat and long values ​​stored in my sqlite database. I am trying to take this list and use it to add circles to api v2 maps using mMap.addCircle by setting circleOptions. How to connect a list of cursors to create circles?

 CircleOptions circleOptions = new CircleOptions()
        .center(new LatLng(location.getLatitude(), location.getLongitude())); 

List of data sources:

public List<Position> getAllPositions() {
    List<Position> position = new ArrayList<Position>();

    Cursor cursor = database.query(MySQLiteHelper.TABLE_NAME,
        allColumns, null, null, null, null, null);

    cursor.moveToFirst();
    while (!cursor.isAfterLast()) { 

        String positions = cursor.getString(1);
    double latitude = cursor.getColumnIndex("lat");
    double longitude = cursor.getColumnIndex("long");

cursor.moveToNext();
    }
    // make sure to close the cursor
    cursor.close();
    return positions;
  }
+3
source share
1 answer

I don’t think that the code will work correctly, firstly, because in the getAllPositions function you return something called "position" that is not visible from there, and even if you return the "position", which is an array of position, it seems empty ...

LatLng

public List<LatLng> getAllPositions() {
List<LatLng> positionList = new ArrayList<LatLng>();

Cursor cursor = database.query(MySQLiteHelper.TABLE_NAME,
    allColumns, null, null, null, null, null);

cursor.moveToFirst();
while (!cursor.isAfterLast()) { 

    String positions = cursor.getString(1);
    double latitude = cursor.getColumnIndex("lat");
    double longitude = cursor.getColumnIndex("long");
    LatLng newLatLng = new LatLng(latitude, longitude);
    positionList.add(newLatLng);
    cursor.moveToNext();
}
// make sure to close the cursor
cursor.close();
return positionList;
}

:

List<LatLng> positionToDraw =  getAllPositions();
for(int i=0;i<positiontoDraw.size();i++){
     CircleOptions circleOptions = new CircleOptions().center(positionToDraw.get(i)); 
     // [...]
}

, .

+1

All Articles