I use the Google Maps Android marker clustering utility from here , and I add a bunch of items (about 700) from the list that I get from my server, I smoothed out my original errors and I see the clusters, then enlarge them and see how they divide to individual markers. However, there are a couple of objects that are far from everyone else, so that even with the maximum reduction, they will never be grouped. For some reason, these elements do not appear on my map, not when I zoom in, not when I zoom out.
I checked the coordinates, they are real, and before I started using clustering, I could see these elements without problems, so I assume that I did something wrong in my clustering code.
Here is the code:
private void setUpClusterer() { // Initialize the manager with the context and the map mClusterManager = new ClusterManager<>(getActivity(), map); vendorRenderer = new VendorRenderer(); mClusterManager.setRenderer(vendorRenderer); mClusterManager.setOnClusterClickListener(this); mClusterManager.setOnClusterItemClickListener(this); //point the maps listeners at the listeners implemented by the cluster manager map.setOnCameraChangeListener(mClusterManager); map.setOnMarkerClickListener(mClusterManager); //add items to the cluster manager addClusterItems(-1); mClusterManager.cluster(); } private void addClusterItems(int positionToMark) { if (null == list) { return; } LatLng position; int maxMarkers = Math.min(list.size(), getResources().getInteger(R.integer.number_of_results_on_map)); mClusterManager.clearItems(); for (int i = 0; i < maxMarkers; i++) { vendorItem = list.get(i); if (vendorItem.getAddress().contains("Remote 1")) { Log.e("Kibi", "Adding Remote 1, pos = " + i); Log.e("Kibi", "Coordinates =" + vendorItem.getPointCoordinates().toString()); } if (vendorItem.getAddress().contains("Clustered 1")) { Log.e("Kibi", "Adding Clustered 1, pos = " + i); Log.e("Kibi", "Coordinates =" + vendorItem.getPointCoordinates().toString()); } if (vendorItem.getAddress().contains("Remote 2")) { Log.e("Kibi", "Adding Remote 2, pos = " + i); Log.e("Kibi", "Coordinates =" + vendorItem.getPointCoordinates().toString()); } VendorMapItem item = new VendorMapItem(vendorItem.getPointCoordinates(), "Some other text"); if (i == positionToMark) { selectedItem = item; } mClusterManager.addItem(item); } if (-1 == positionToMark) { selectedItem = null; } }
This shows the addition of elements. The entries added by me allow me to see that my 2 deleted elements were added with good coordinates and my (though visible) similar (although remote) selected clustered element (which is visible)
Here is the visualization code:
private class VendorRenderer extends DefaultClusterRenderer<VendorMapItem> { Context context = getActivity().getApplicationContext(); public final IconGenerator mIconGenerator = new IconGenerator(context); public final IconGenerator mSelectedIconGenerator = new IconGenerator(context); private final View mItemView; private final View mSelectedItemView; public VendorRenderer() { super(getActivity().getApplicationContext(), map, mClusterManager);
In the general case, cluster elements are displayed, as well as delineated ones, regardless of whether they are selected or not. I have another view showing all the location data in the list, and my remote locations only show the fins there.
Any ideas what I'm doing wrong?