sql >> Databasteknik >  >> RDS >> SQLite

Android - Cursor onMapReady (Markörer)

Äntligen lyckades jag fixa det, hoppas det här hjälper någon.

Min ParkDataSource:

public Cursor getAll() {
        return db.rawQuery("SELECT * FROM " + SQLiteHelper.TABLE_PARKS,
                null);
    }

Mitt fragment:

SQLiteHelper dbHelper = new SQLiteHelper(getActivity());
        pds = new ParksDataSource(dbHelper.db);
        cursor = pds.getAll();

        List<Marker> markersList = new ArrayList<Marker>();
        int i = 0;
        try {
            while (cursor.moveToNext()) {
                String[] latlong = cursor.getString(cursor.getColumnIndex(SQLiteHelper.COL_PARKS_COORDINATES)).split(",");
                double latitude = Double.parseDouble(latlong[0]);
                double longitude = Double.parseDouble(latlong[1]);
                mark = new LatLng(latitude, longitude);

                if (cursor.getString(cursor.getColumnIndex(SQLiteHelper.COL_PARKS_SLOTS)) == null){

                    Marker mPark = map.addMarker(new MarkerOptions().position(mark)
                            .title(cursor.getString(cursor.getColumnIndex(SQLiteHelper.COL_PARKS_TITLE)))
                            .icon(BitmapDescriptorFactory.fromBitmap(writeTextOnDrawable(R.mipmap.ic_pin, cursor.getString(cursor.getColumnIndex(SQLiteHelper.COL_PARKS_FREE))))));
                    mPark.setTag(0);
                    markersList.add(mPark);
                }
                i++;
            }
        } finally {
            cursor.close();
        }

        LatLngBounds.Builder builder = new LatLngBounds.Builder();
        for (Marker m : markersList) {
            builder.include(m.getPosition());
        }



  1. Datamaskering i DB-applikationer

  2. Materialiserade vyer - Identifiera den senaste uppdateringen

  3. Hur man läser och återställer AUTO_INCREMENT i MySQL

  4. Hur funktionen tidszon() fungerar i PostgreSQL