How can inflate addmarker from Cursor SQLITE?

2019-08-24 17:15发布

问题:

Im try inflate follow these example

public void onMapReady(GoogleMap googleMap) {
    cursor = mb.listar();
    mMap = googleMap;
    // Add a marker in Sydney and move the camera
    //LatLng sydney = new LatLng(-34, 151);
   // mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
    //mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
}

And my methods are

CajeroDAO

public Cursor getAll() throws SQLException {
    Cursor c = MiBD.getDB().query(true, CAJEROS_TABLE, CAMPOS_CAJEROS, null, null, null, null, null, null);
    return c;
}

And

MiCajeroOperacional

public Cursor listar() {
    return cajero.getAll();
}

Then, as I add cursor marks for each of them?

Solution for my problem Here post my solution for center and add markers from cursor, is easy quick solution.

@Override
    public void onMapReady(GoogleMap googleMap) {
        cursor = mb.listar();
        mMap = googleMap;
        LatLng mark = null;

        List<Marker> markersList = new ArrayList<Marker>();
        int i = 0;
        while (cursor.moveToNext()) {
            double lat = cursor.getDouble(cursor.getColumnIndex("lat"));
            double lng = cursor.getDouble(cursor.getColumnIndex("lng"));
            mark = new LatLng(lat, lng);
            Marker markCajero = mMap.addMarker(new MarkerOptions().position(mark).title("Sucursal Nº" + i).snippet(cursor.getString(cursor.getColumnIndex("direccion"))));
            // mMap.moveCamera(CameraUpdateFactory.newLatLng(mark), 15);
            markersList.add(markCajero);
            i++;
        }
        cursor.close();
        builder = new LatLngBounds.Builder();
        for (Marker m : markersList) {
            builder.include(m.getPosition());
        }
        int padding = 50;
        LatLngBounds bounds = builder.build();
        cu = CameraUpdateFactory.newLatLngBounds(bounds, padding);
        mMap.moveCamera(cu);

    }