我正在尝试将我的内容从SQLite“膨胀”到标记中,但我使用的here解决方案不起作用,而且它没有在Log上提供任何信息。
我对这个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());
}`
感谢您的时间。
答案 0 :(得分:0)
最后我设法解决了这个问题,希望能帮助别人。
我的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());
}