Blacksword Blacksword - 1 year ago 90
Android Question

Pass data inside Clustered Marker

I am really struggling with google map util these days challenge after challenge and there is not good example or solution on the net.

This is my code:

protected void onBeforeClusterRendered(Cluster<ItemCluster> cluster,
MarkerOptions markerOptions) {

View marker = (getActivity()
.inflate(R.layout.info_windows, null);

Bitmap bitmap = createDrawableFromView(
getActivity(), marker);



The problem is before I send the view to this function to make a bitmap for marker, I try to set some data in my info_windows.xml which is included with some ImageViews and TextViews. But the app hangs, do you have any idea how to make this done?

Bitmap bitmap = createDrawableFromView(
getActivity(), marker);

Answer Source

I solve my problem by making an IconGenerator objectand then make the view from that this is how i did it:

first i made the object:

private final IconGenerator mClusterIconGenerator = new IconGenerator(getActivity().getApplicationContext());

and a view which contains our XML view file of our costum marker:

View markerIcon = getActivity().getLayoutInflater().inflate(R.layout.marker_icon, null);

then set the view on icongenerator:


then you need to initiate your imageview, textview, ... then set the values that you want to show inside your costum marker like this for ex:

mMarkerViento = (ImageView) clusterIcon.findViewById(;

then inside the ovveride method of:

        protected void onBeforeClusterItemRendered(ItemCluster item, MarkerOptions markerOptions)


and at the end you generate your bitmap object from icon generator like this:

   mMarkerIconGenerator.setBackground(TRANSPARENT_DRAWABLE); // set the background as transparent
    Bitmap bitmap = mMarkerIconGenerator.makeIcon(); // make a bitmap object from the icon object
    markerOptions.icon(BitmapDescriptorFactory.fromBitmap(bitmap)); // set the bitmap as marker icon

good luck and tanx

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download