jeudi 8 janvier 2015

Retrieving markerId from SQLite database does not display the image

In my app i can add a marker with image from camera intent, the display that image via markerId. Then i had to create a SQLite database to save all that information so when user returns to app and tap on the marker, the image should then be displayed.


So I was told to save the markerId to Sqlite and then retrieve that id when the mapp starts again, but it doesn't seem to work. I don't get any error messages or anything but the image does not display.


So here is my code when adding the marker:



Marker marker = googleMap.addMarker(new MarkerOptions()
.title(title.getText().toString())
.snippet(snippet.getText().toString())
.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_BLUE))
.position(point));
markerId = marker.getId();


then when saving the markerId :



contentValues.put(LocationsDB.FIELD_IMAGE, markerId);


then when drawing the marker to the map:



private void drawMarker(LatLng point, String title, String snippet, byte[] id) {
Marker marker = googleMap.addMarker(new MarkerOptions()
.title(title)
.snippet(snippet)
.position(thePoint));
markerId = marker.getId();


And retrieving data from SQlite:



public void onLoadFinished(Loader<Cursor> arg0, Cursor arg1) {
int locationCount = 0;
double lat=0;
double lng=0;
float zoom=0;
String title = null;
String snippet = null;
byte [] id = null;
locationCount = arg1.getCount();
arg1.moveToFirst();

for(int i=0;i<locationCount;i++){

lat = arg1.getDouble(arg1.getColumnIndex(LocationsDB.FIELD_LAT));
lng = arg1.getDouble(arg1.getColumnIndex(LocationsDB.FIELD_LNG));
zoom = arg1.getFloat(arg1.getColumnIndex(LocationsDB.FIELD_ZOOM));
title = arg1.getString(arg1.getColumnIndex(LocationsDB.FIELD_TITLE));
snippet = arg1.getString(arg1.getColumnIndex(LocationsDB.FIELD_SNIPPET));
id = arg1.getBlob(arg1.getColumnIndex(LocationsDB.FIELD_IMAGE));
thePoint = new LatLng(lat, lng);
drawMarker(thePoint, title, snippet, id);
if(myMarkersHash.get(id) != null)
markerIcon.setImageBitmap(BitmapFactory.decodeByteArray(imageData, 0,
imageData.length));
arg1.moveToNext();
}

if(locationCount>0){
googleMap.moveCamera(CameraUpdateFactory.newLatLng(new LatLng(lat,lng)));
googleMap.animateCamera(CameraUpdateFactory.zoomTo(zoom));


So when adding the marker initially i can see the image when tapping on the marker, but when exiting and returning to the map the marker is there but no image when tapping on the marker.


EDIT I also had to do this:



baos = new ByteArrayOutputStream();
bitmap.compress(CompressFormat.PNG, 100, baos);
imageData = baos.toByteArray();


So not sure what to do now as everything is saved to the database but can't retrieve the image.


Any help would be appreciated.


Thanks


EDIT 2*


When displaying the image for that specific marker:



baos = new ByteArrayOutputStream();
bitmap.compress(CompressFormat.PNG, 100, baos);
imageData = baos.toByteArray();
myMarkersHash.put(markerId, bitmap);


So do i need to save that bitmap as well to database or just the markerId?


Aucun commentaire:

Enregistrer un commentaire