So I'm using a ClusterManager
to cluster my Markers
, so that the user can have a better experience.
I have actually implemente Google's code, which I found here. Imagine now that my Marker
icon is a ball. I want the background of the icon to be transparent, not white.
On Google's original tutorial they set a ImageView
to the IconGenerator
, like this:
public class MyClusterManagerRenderer extends DefaultClusterRenderer<ClusteredMarker> {
private final IconGenerator mIconGenerator;
private final ImageView mImageView;
public MyClusterManagerRenderer(Context context, GoogleMap googleMap,
ClusterManager<ClusteredMarker> clusterManager){
super(context, googleMap, clusterManager);
mIconGenerator = new IconGenerator(context);
mImageView = new ImageView(context);
mIconGenerator.setContentView(mImageView);
}
@Override
protected void onBeforeClusterItemRendered(ClusteredMarker item, MarkerOptions markerOptions) {
mImageView.setImageResource(item.iconPicture);
Bitmap icon = mIconGenerator.makeIcon();
markerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon)).title(item.user);
}
...
}
I have tried several ways to make my icon transparent, like calling:
mImageView.setBackgroundColor(Color.TRANSPARENT);
but without success. The only way I managed to find a solution is to directly attach my transparent image to the IconGenerator
, like this:
mIconGenerator.setBackground(aContext.getResources().getDrawable(R.drawable.ball));
The downside of this approach is that a ImageView
have some interesting methods that I would like to call, like setPadding
, while the IconGenerator
doesn't have that.
So, is there a way to make my icon transparent, using the ImageView
?
Thank you,
For adding a custom marker to Google Maps navigate to the app > res > drawable > Right-Click on it > New > Vector Assets and select the icon which we have to show on your Map. You can change the color according to our requirements. After creating this icon now we will move towards adding this marker to our Map.
Markers are objects of type Marker , and are added to the map with the GoogleMap. addMarker(markerOptions) method. Markers are designed to be interactive. They receive click events by default, and are often used with event listeners to bring up info windows.
The solution I found is this:
private static final Drawable TRANSPARENT_DRAWABLE = new ColorDrawable(Color.TRANSPARENT);
// Make the background of marker transparent
mIconGenerator.setBackground(TRANSPARENT_DRAWABLE);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With