2

i'm developing my app that use markers on google map. Then i use clustering to gather markers that are too closer. Here is part of my code:

MapViewer.java

public class MapViewer extends Activity implements OnInfoWindowClickListener {

    private GoogleMap map;
    private ClusterManager<MyItem> mClusterManager;

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.mapviewer);

        try {
            map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
            if (map != null) {
                map.setMyLocationEnabled(true);
                map.setMapType(GoogleMap.MAP_TYPE_NORMAL);
                map.getUiSettings().setRotateGesturesEnabled(false);


                mClusterManager = new ClusterManager<MyItem>(this, map);
                mClusterManager.setRenderer(new MyClusterRenderer(this, map, mClusterManager));

                map.setOnCameraChangeListener(mClusterManager);
                map.setOnMarkerClickListener(mClusterManager);

                map.setInfoWindowAdapter(new ClusterInfoWindow(getLayoutInflater()));
                map.setOnInfoWindowClickListener(this);

                addItems();
            }
        } catch (NullPointerException e) {
            e.printStackTrace();
        }
    }

    @Override
    public void onInfoWindowClick(Marker marker) {
        // My code
    }

    public void addItems() {
        // My code
    }
}

ClusterInfoWindow.java

public class ClusterInfoWindow implements InfoWindowAdapter {
    LayoutInflater inflater = null;

    public ClusterInfoWindow(LayoutInflater inflater) {
        this.inflater = inflater;
    }

    @Override
    public View getInfoWindow(Marker marker) {
        return(null);
    }

    @Override
    public View getInfoContents(Marker marker) {
        View popup = inflater.inflate(R.layout.infowindow, null);

        TextView tv = (TextView)popup.findViewById(R.id.title);

        tv.setText(marker.getTitle());
        tv = (TextView)popup.findViewById(R.id.snippet);
        tv.setText(marker.getSnippet());

        return(popup);
    }
}

If i click on single marker it shows a popup with some details. The same happens if i click on a cluster. How to make the cluster not clickable? I don't want to show anything when user click on cluster. Thank you.

smartmouse
  • 13,912
  • 34
  • 100
  • 166
  • I just got a solution working that does just this, it shows InfoWindows for Markers, but not for Clusters. Have a look here: http://stackoverflow.com/questions/30958224/android-maps-utils-clustering-show-infowindow/30959578#30959578 – Daniel Nugent Jun 21 '15 at 02:16

2 Answers2

0

Based on the documentation from Google Maps:

If you want to add specific functionality in response to a marker click event, set the map's OnMarkerClickListener() to the ClusterManager, since ClusterManager implements the listener.

So, instead of doing map.setOnMarkerClickListener(mClusterManager); you can change it to the following:

map.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
            @Override
            public boolean onMarkerClick(Marker marker) {
                marker.showInfoWindow();
                return false;
            }
       });
ztan
  • 6,861
  • 2
  • 24
  • 44
0

You want to implement ClusterManager.OnClusterItemClickListener or ClusterManager.OnClusterItemInfoWindowClickListener

Paul
  • 151
  • 1
  • 5