Marker.setIcon throws java.lang.IllegalArgumentException: unmanaged handle

I'm having trouble changing the googlemap token to googlemap.

None of these methods work.

MarkerOptions markerOptions = new MarkerOptions().icon(BitmapDescriptorFactory.fromBitmap(MarkerManager.getBitmapFromVectorDrawable(context, R.drawable.marker_no_issues)));
                    marker.setIcon(markerOptions.getIcon());

and

marker.setIcon(BitmapDescriptorFactory.fromBitmap(MarkerManager.getBitmapFromVectorDrawable(context, R.drawable.marker_no_issues)));

GetBitmapFromVectorDrawable method:

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 am I doing wrong? Why can't I change the marker icon using the setIcon method. I also tried raw.png files, and I know that a vector for a bitmap works well.

+4
source share
2 answers

I had the same problem as it should - before installing the icon on the marker object, just check if the marker is visible on googlemap If you clear the map and set the icon on this marker object on the map, this error will result

setter

+4

fooobar.com/questions/196137/...: " setIcon() , , setIcon() ".

(. fooobar.com/questions/989125/...). , , , @Kaveri , .

, .

private var selectedItem: StationClusterItem? = null

override fun onMapReady(googleMap: GoogleMap) {
    ...

    val clusterRenderer = MarkerClusterRenderer(context!!, googleMap, clusterManager!!,
        unselectedBitmap!!)
    clusterManager?.setOnClusterItemClickListener { item ->
        if (selectedItem != null) {
            // Set here a reference to a previous marker.
            // We save a reference to a previous item, not to a marker.
            val lastMarker = clusterRenderer.getMarker(selectedItem)
            lastMarker?.setIcon(unselectedBitmap)
        }
        selectedItem = item
        // Now get a reference to a selected marker.
        val newMarker = clusterRenderer.getMarker(item)
        newMarker?.setIcon(selectedBitmap)
        false
    }
}
0

Source: https://habr.com/ru/post/1677654/


All Articles