I have saved all the relevant information needed to reload the markers once the app has restarted. Now the problem is it just reloads the title and snippet but not the image associated with that marker:
So in my database this is what is saved: (after the = its the value saved and in () the column name
Column 1 = 1 (id)
column 2 = xx.xxx (lng)
column 3 = xx.xxx (lat)
column 4 = 9.0 (zoom)
column 5 = test (title)
column 6 = marker (snippet)
column 7 = m12 (marker id)
column 8 = /storage/emulated/0/Images/myimage_yyyymmdd_hhmmss.jpg (imagepath)
So as you can see all the information is saved to reload the marker with the title, snippet, zoom level as well as the image and latlng point.
But however when restarting the map the marker is displayed on the correct location with the title and the snippet, but the image isn't displayed (the image is displayed in the CustomInfoWindow
So here is the code to save the values and to retrieve them:
contentValues.put(LocationsDB.FIELD_LAT, point.latitude);
contentValues.put(LocationsDB.FIELD_LNG, point.longitude);
contentValues.put(LocationsDB.FIELD_ZOOM, googleMap.getCameraPosition().zoom);
contentValues.put(LocationsDB.FIELD_TITLE, title.getText().toString());
contentValues.put(LocationsDB.FIELD_SNIPPET, snippet.getText().toString());
contentValues.put(LocationsDB.FIELD_IMAGE, markerId);
contentValues.put(LocationsDB.FIELD_FILEPATH, image.getAbsolutePath());
.....
@Override
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;
String id = null;
String filep = 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.getString(arg1.getColumnIndex(LocationsDB.FIELD_IMAGE));
filep = arg1.getString(arg1.getColumnIndex(LocationsDB.FIELD_FILEPATH));
thePoint = new LatLng(lat, lng);
drawMarker(thePoint, title, snippet, id, filep);
View v = getLayoutInflater().inflate(R.layout.infowindow_layout, null);
ImageView markerIcon = (ImageView) v.findViewById(R.id.marker_icon);
Bitmap myImage = BitmapFactory.decodeFile(filep);
markerIcon.setImageBitmap(myImage);
arg1.moveToNext();
}
if(locationCount>0){
googleMap.moveCamera(CameraUpdateFactory.newLatLng(new LatLng(lat,lng)));
googleMap.animateCamera(CameraUpdateFactory.zoomTo(zoom));
}
}
And for when drawing the marker on the map:
private void drawMarker(LatLng point, String title, String snippet, String id, String filep) {
Marker marker = googleMap.addMarker(new MarkerOptions()
.title(title)
.snippet(snippet)
.position(thePoint));
markerId = marker.getId();
}
So what am i doing wrong here and do i need to somehow when the marker gets drawing to say load id and image path?
Could someone please shed some light on this for me?
Thanks