1

I'm using Google Map SDK 7.3.0 with android-maps-utils 0.3.4 because I need clusters for my Markers on the map.

My map

Ok, so here the problem is, I shouldn't have a red marker. Only green+blue markers. I subclassed DefaultClusterRenderer to create my custom marker view but sometimes it just doesn't work.

I'm using picasso to get the green icon because it's coming from an API. But the problem is, when picasso has loaded the bitmap it's too late, the icon has already been set to the default one (red).

Here's my onBeforeClusterItemRenderer :

            Picasso.with(getApplicationContext()).load(item.url).into(new Target() {
            @Override
            public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
                FrameLayout icon = (FrameLayout) LayoutInflater.from(getApplicationContext()).inflate(R.layout.marker, null);
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                    icon.findViewById(R.id.bg).setBackground(new BitmapDrawable(getResources(), bitmap));
                } else {
                    icon.findViewById(R.id.bg).setBackgroundDrawable(new BitmapDrawable(getResources(), bitmap));
                }


                Bitmap b = createDrawableFromView(Home.this, icon);

                if (marker != null) {
                    marker.icon(BitmapDescriptorFactory.fromBitmap(b));
                }
            }

            @Override
            public void onBitmapFailed(Drawable errorDrawable) {

            }

            @Override
            public void onPrepareLoad(Drawable placeHolderDrawable) {

            }
        });
Quentin DOMMERC
  • 876
  • 1
  • 8
  • 24
  • You post some code about how you add the markers(clusters) to your mapview and your code of the `DefaultClusterRenderer` subclass. Also, do the red markers show up because there is only one marker in those area? If there are more than 1, they will become cluster icons? – ztan Apr 29 '15 at 16:55
  • @ztan My `onBeforeClusterItemRendered` is a bit complicated as I use a custom view inflated from a xml then add a bitmap from picasso, then because it's a marker, get a bitmap of that layout. – Quentin DOMMERC Apr 30 '15 at 07:55
  • This is because you are using an anonymous class as your target.. for every marker you need to create a new target and store a reference to it in a list or hashmap, that way it won't be garbage collected and will be updated once the bitmap has successfully downloaded. – speedynomads Mar 24 '17 at 21:03

1 Answers1

5

--- EDITED ---

When downloading the image inside onBeforeClusterItemRendered you are actually downloading the image every time the Cluster Manager tries to load a marker, so if you have, for example, 100 markers you will download the image 100 times.

You should download the image inside onCreate, save it in a static variable, call mClusterManager.cluster(); after saving the image, and finally inside onBeforeClusterItemRendered wrtie marker.icon(BitmapDescriptorFactory.fromBitmap(YourActivity.b));

MauriF
  • 682
  • 6
  • 19
  • Nope, I shouldn't have them at all. I have my `onBeforeClusterItemRendered` so I shouldn't have the red marker. – Quentin DOMMERC May 03 '15 at 06:40
  • Oh i get it now, so you are able to download the image and use it as a marker icon but sometimes it just shows a red marker icon. You should post your `onBeforeClusterItemRendered` code then.. – MauriF May 03 '15 at 18:40