Blacksword Blacksword - 1 month ago 14
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:

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

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


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

markerOptions.icon(BitmapDescriptorFactory.fromBitmap(bitmap));

}


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

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:

mMarkerIconGenerator.setContentView(markerIcon);

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(R.id.viento);

then inside the ovveride method of:

    @Override
        protected void onBeforeClusterItemRendered(ItemCluster item, MarkerOptions markerOptions)

               mMarkerViento.setImageResource(R.drawable.viento_ne2);

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