本文介绍了Android-Cursor onMapReady(标记)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将我的内容从SQLite充气"到Markers中,但是我采用的解决方案是不起作用,也没有在Log上抛出任何信息.

I'm trying to "inflate" my content from SQLite into Markers but the solution I took of here it's not working, and it's not throwing any information on Log.

在Marker和SQLite上我有点新了

I'm a bit new on this Marker stuff and SQLite

我在Fragment中的代码:

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

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

谢谢您的时间.

推荐答案

最后我设法解决了这个问题,希望对大家有所帮助.

Finally I managed to fix it, hope this help someone.

我的ParkDataSource:

My ParkDataSource:

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

这篇关于Android-Cursor onMapReady(标记)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-03 12:28
查看更多