1

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);
Sufian
  • 6,405
  • 16
  • 66
  • 120
Blacksword
  • 331
  • 3
  • 17
  • Check this solution : http://stackoverflow.com/questions/25968486/how-to-add-info-window-for-clustering-marker-in-android In DefaultClusterRenderer class you can't inflate your info view – Naveen Kumar M Aug 31 '16 at 12:12
  • thanks, but i don't wanna add infoWindow the thing i wanna do is manipulate the cluster marker and show some data (temperature average of cluster items) – Blacksword Aug 31 '16 at 12:33
  • can you paste createDrawableFromView method – Naveen Kumar M Sep 10 '16 at 06:55
  • @NaveenKumarM it wasn´t a good idea try to use `IconGenerator` because for some reason you can't manipulate the views inside your xml icon impelement like this: `private final IconGenerator mClusterIconGenerator = new IconGenerator(getActivity().getApplicationContext());` and `mClusterIconGenerator.setBackground(TRANSPARENT_DRAWABLE); Bitmap bitmap = mClusterIconGenerator.makeIcon(String.valueOf(cluster.getSize())); markerOptions.icon(BitmapDescriptorFactory.fromBitmap(bitmap));` – Blacksword Sep 12 '16 at 07:46

1 Answers1

0

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

Blacksword
  • 331
  • 3
  • 17