0

I am using Android Maps Utils. I am reading a list of coordinates from online and plotting them as cluster items as well as saving them in a hash map which associates a "Room" a class I have created to the cluster item:

private HashMap roomHashMap = new HashMap();

On clicking the info window of this cluster item I need to retrieve the room associated with the cluster item. I had implemented this using a marker with no problem as in the onInfoWindowClickListener I just added roomHashMap.get(marker) but now I cannot do this because in the info window it still requires a marker but I have a HashMap of ClusterItem

   mMap.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() {

        @Override
        public void onInfoWindowClick(Marker marker) {

            //Ideally I want this
           //Room currenRoom=roomHashMap.get(clusterItem);
          //but clusterItem is obviously not a Marker
        }

    });
hakobob
  • 81
  • 7
  • You need to use `OnClusterItemInfoWindowClickListener` and use the `onClusterItemInfoWindowClick()` callback , take a look at this answer: http://stackoverflow.com/questions/30958224/android-maps-utils-clustering-show-infowindow/30959578#30959578 – Daniel Nugent Jul 14 '15 at 01:15
  • Thank you! Perfectly what I wanted – hakobob Jul 30 '15 at 00:25

1 Answers1

0
        googleMap = mFragment.getMap();
        googleMap.setMapType(GoogleMap.MAP_TYPE_TERRAIN);
        googleMap.getUiSettings().setZoomControlsEnabled(true); // true to
        googleMap.getUiSettings().setZoomGesturesEnabled(true);
        googleMap.getUiSettings().setCompassEnabled(true);
        googleMap.getUiSettings().setMyLocationButtonEnabled(true);
        googleMap.getUiSettings().setRotateGesturesEnabled(true);
        if (googleMap == null) {
            Toast.makeText(getActivity(), "Sorry! unable to create maps",
                    Toast.LENGTH_SHORT).show();
        }
        mClusterManager = new ClusterManager<MyItem>(getActivity(),             googleMap );
        googleMap.setOnMapLoadedCallback(this);
        googleMap.setMyLocationEnabled(true);
        googleMap.setBuildingsEnabled(true);
        googleMap.getUiSettings().setTiltGesturesEnabled(true);

        markers = new Hashtable<String, String>();
        mClusterManager.setRenderer(new MyClusterRenderer(getActivity() ,     googleMap , mClusterManager ));

public class MyClusterRenderer extends DefaultClusterRenderer {

public MyClusterRenderer(Context context, GoogleMap map,
        ClusterManager<MyItem> clusterManager) {
    super(context, map, clusterManager);
}

@Override
protected void onBeforeClusterItemRendered(MyItem item, MarkerOptions markerOptions) {
    super.onBeforeClusterItemRendered(item, markerOptions);

    markerOptions.title(item.getTitle());
    markerOptions.snippet(item.getAddress());
}

@Override
protected void onClusterItemRendered(MyItem clusterItem, Marker marker) {
    super.onClusterItemRendered(clusterItem, marker);
    //here you have access to the marker itself
}

}