Android - 光标 onMapReady(标记)

Android - Cursor onMapReady (Markers)

我正在尝试 "inflate" 我的内容从 SQLite 到标记中,但我采用的解决方案 here 它不起作用,并且它没有在日志中抛出任何信息。

我对 Marker 和 SQLite 有点陌生

我的代码在Fragment里面:

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

    parks = pds.getAllParks();

    List<Marker> markersList = new ArrayList<Marker>();
    int i = 0;
    Cursor cursor = db.rawQuery("SELECT * FROM " + SQLiteHelper.TABLE_PARKS,
            null);
    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);
            Marker mPark = mMap.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);
            Log.d("HierParks", "Pin: " + i + ", " + latitude + "," + longitude + " - Park:" + cursor.getString(cursor.getColumnIndex(SQLiteHelper.COL_PARKS_TITLE)));
            i++;
        }
    } finally {
        cursor.close();
    }

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

感谢您的宝贵时间。

终于解决了,希望对大家有帮助。

我的公园数据源:

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

我的片段:

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());
        }