I have saved the marker ID as well as the Image file path in my app using SQLite database. The problem I am experiencing at the moment is when loading the map again the markers are displayed where the user has added them, but the image taken for that marker via camera intent (image path) does not load with the marker.
So to explain, my markers have a CustomInfoWindow
that the displays a title and snippet (location of marker) then has an ImageView
which does display the image initially once the marker has been placed. But when reloading the app the image is gone but the Title and Snippet is displayed.
So when saving the image file path and marker ID I use:
contentValues.put(LocationsDB.FIELD_IMAGE, markerId);
contentValues.put(LocationsDB.FIELD_FILEPATH, image.getAbsolutePath());
The data it saves is this:
m15 --> Marker ID
/storage/emulated/0/My Folder/MyImage_123.jpg --> File Path
And then when loading the markers once the app starts:
String filep = null;
String id = null;
id = arg1.getString(arg1.getColumnIndex(LocationsDB.FIELD_IMAGE));
filep = arg1.getString(arg1.getColumnIndex(LocationsDB.FIELD_FILEPATH));
drawMarker(thePoint, title, snippet, id, filep);
So then in my drawMarker
method:
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)
.icon(BitmapDescriptorFactory
.defaultMarker(BitmapDescriptorFactory.HUE_BLUE)));
markerId = marker.getId();
And when dislaying the initial image, title and snippet:
@Override
public View getInfoContents(Marker marker)
{
View v = getLayoutInflater().inflate(R.layout.infowindow_layout, null);
ImageView markerIcon = (ImageView) v.findViewById(R.id.marker_icon);
TextView titleText = (TextView) v.findViewById(R.id.TitleId);
titleText.setText(marker.getTitle());
TextView snippetText = (TextView) v.findViewById(R.id.SnippetId);
snippetText.setText(marker.getSnippet());
Bitmap bitmap = myMarkersHash.get(marker.getId());
markerIcon.setImageBitmap(bitmap);
return v;
So I know I need to somehow (in the drawMarker method) implement the filep
and id
so that i can display the image for that marker. But am not sure how to do that. I don't want to substitute the icon for the image instead i want the default marker with the image in the imageview.
I have been struggling with this for a couple of weeks now. So now I am hoping that someone will be able to help.
Aucun commentaire:
Enregistrer un commentaire