I'm using the library Google Maps Utility for Android which allows to create clustering int he maps and I need to show a custom InfoWindow
but I can't find any method to do this.
In order to show the info window, I have the following class, and in the method onClusterItemRendered
is where I have access to the info of the marker:
class MyClusterRenderer extends DefaultClusterRenderer<MarkerItem> {
public MyClusterRenderer(Context context, GoogleMap map,
ClusterManager<MarkerItem> clusterManager) {
super(context, map, clusterManager);
}
@Override
protected void onBeforeClusterItemRendered(MarkerItem item,
MarkerOptions markerOptions) {
super.onBeforeClusterItemRendered(item, markerOptions);
markerOptions.title(String.valueOf(item.getMarkerId()));
}
@Override
protected void onClusterItemRendered(MarkerItem clusterItem,
Marker marker) {
super.onClusterItemRendered(clusterItem, marker);
}
}
Is there anybody who has used the library and knows how to show a custom InfoWindow
such as the way it was used in the Google Maps? Like:
getMap().setInfoWindowAdapter(new InfoWindowAdapter() {
@Override
public View getInfoWindow(Marker arg0) {
return null;
}
@Override
public View getInfoContents(Marker arg0) {
return null;
}
});
Yes, this can be done.
ClusterManager
maintains twoMarkerManager.Collections
:You can set a custom
InfoWindowAdapter
for each of these kinds of markers independently.Implementation
First, install your ClusterManager's MarkerManager as the map's InfoWindowAdapter:
Next, install your custom
InfoWindowAdapter
as the adapter for one or both of the marker collections:The final piece is mapping the raw
Marker
object that you'll receive in your custom InfoWindowAdapter's callback to theClusterItem
object(s) that you added to the map in the first place. This can be achieved using the onClusterClick and onClusterItemClick listeners, as follows:Now you have everything you need to assemble your custom InfoWindow content in your respective Adapters! For example:
So basically you have your class starting like this:
So in that parameter
map
of the typeGoogleMap
is where you have to specify yoursetInfoWindowAdapter
.