I am having trouble with changing googlemap marker on the googlemap.
Neither this method works
MarkerOptions markerOptions = new MarkerOptions().icon(BitmapDescriptorFactory.fromBitmap(MarkerManager.getBitmapFromVectorDrawable(context, R.drawable.marker_no_issues)));
marker.setIcon(markerOptions.getIcon());
nor this
marker.setIcon(BitmapDescriptorFactory.fromBitmap(MarkerManager.getBitmapFromVectorDrawable(context, R.drawable.marker_no_issues)));
Method getBitmapFromVectorDrawable:
public static Bitmap getBitmapFromVectorDrawable(Context context, int drawableId) {
Drawable drawable = AppCompatDrawableManager.get().getDrawable(context, drawableId);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
drawable = (DrawableCompat.wrap(drawable)).mutate();
}
Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(),
drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
drawable.draw(canvas);
return bitmap;
}
What i am doing wrong? Why i cant change marker icon with setIcon method. I have also tried raw .png files and i know that vector to bitmap works well.
I had the same problem solved this as follows - before setting the icon to the marker object just check if the marker is still visible on googlemap If you had cleared the map and setting the icon to this marker object on map, would result in this error
In that case, just create another new object instead of updating the same object by setter methods
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With