I'm clustering markers using the google maps api. Since I want a custom icon as a marker, I've created a custom renderer (that extends DefaultClusterRenderer
). On onBeforeClusterItemRendered
I'm setting the desired icon.
The problem is that I now want to create a custom infowindow
. If I do:
googleMap.setInfoWindowAdapter(new InfoWindowAdapter() {
// Use default InfoWindow frame
@Override
public View getInfoWindow(Marker arg0) {
return null;
}
// Defines the contents of the InfoWindow
@Override
public View getInfoContents(Marker arg0) {
}
});
In the getInfoContents
I can customize the infowindow. The problem is that the passed params are of type Marker
. Because I'm using clustering I'm using a custom marker (MyMarker
) that as info in it.
I can't cast Marker
to MyMarker
nor can change the params to MyMarker
. I wan't to do this to extract the info.
How can I still maintain the clustering (here I can access MyMarker
info) but creating a custom infowindow?
public MarkerRenderer() {
super(getActivity(), mGoogleMap, mClusterManager);
}
@Override
protected void onBeforeClusterItemRendered(MyMarker myMarker, MarkerOptions markerOptions) {
markerOptions.icon(BitmapDescriptorFactory.fromResource(myMarker.getMarkerImage())).title(
"This is my custom marker with the default infoWindo");
}
@Override
protected void onBeforeClusterRendered(Cluster<MyMarker> cluster, MarkerOptions markerOptions) {
super.onBeforeClusterRendered(cluster, markerOptions);
markerOptions.title("cluster size " + cluster.getSize());
}