ClusteredMarkers Android cards - don't show non-clustered?

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:

 /* This draws the markers for us */ 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); // Create selected custom Marker RelativeLayout selectedContainer = (RelativeLayout) view.findViewById(R.id.marker_map_selected_container); mSelectedItemView = ((LayoutInflater) getActivity().getSystemService (Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.map_marker_selected_layout, selectedContainer, false); mSelectedIconGenerator.setContentView(mSelectedItemView); mSelectedIconGenerator.setBackground(null); // Create custom Marker LinearLayout container = (LinearLayout) view.findViewById(R.id.text_marker_map_container); mItemView = ((LayoutInflater) getActivity().getSystemService (Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.map_marker_layout, container, true); mIconGenerator.setContentView(mItemView); mIconGenerator.setBackground(null); } @Override protected void onBeforeClusterItemRendered(VendorMapItem vendor, MarkerOptions markerOptions) { // Draw a single vendor. Bitmap icon; if (null == selectedItem || !vendor.getPosition().equals(selectedItem.getPosition())) { icon = mIconGenerator.makeIcon(); } else { icon = mSelectedIconGenerator.makeIcon(); } markerOptions.title(vendor.getTitle()); markerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon)); } @Override protected void onBeforeClusterRendered(Cluster<VendorMapItem> cluster, MarkerOptions markerOptions) { // Draw multiple vendors clustered... Bitmap icon = mIconGenerator.makeIcon(); markerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon)); } @Override protected boolean shouldRenderAsCluster(Cluster cluster) { // Always render clusters. return cluster.getSize() > 1; } } 

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?

+8
android google-maps-android-api-2 google-maps-markers markerclusterer
source share
2 answers

Stupidity.

I basically called map.clear () too many times. I think there is no need to bring clarity if all that is drawn on the map is contacts that are controlled by the cluster. After deleting cells (), my contacts will appear again.

+1
source share

The public class ClusterIconProvider implements IconDataProvider {

 private static final int[] res = {R.drawable.m1,R.drawable.m2,R.drawable.m3,R.drawable.m4,R.drawable.m5}; private static final int[] forCounts = { 10, 100, 1000, 10000, Integer.MAX_VALUE }; private Bitmap[] baseBitmaps; private Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); private Rect bounds = new Rect(); private MarkerOptions markerOptions = new MarkerOptions().anchor(0.5f, 0.5f); public ClusterIconProvider(Resources resources){ baseBitmaps = new Bitmap[res.length]; for (int i = 0; i < res.length; i++) { baseBitmaps[i] = BitmapFactory.decodeResource(resources, res[i]); } paint.setColor(Color.WHITE); paint.setTextAlign(Align.CENTER); paint.setTextSize(resources.getDimension(R.dimen.Cluster)); } @Override public MarkerOptions getIconData(int markersCount) { // TODO Auto-generated method stub Bitmap base; int i = 0; do { base = baseBitmaps[i]; } while (markersCount >= forCounts[i++]); Bitmap bitmap = base.copy(Config.ARGB_8888, true); String text = String.valueOf(markersCount); paint.getTextBounds(text, 0, text.length(), bounds); float x = bitmap.getWidth() / 2.0f; float y = (bitmap.getHeight() - bounds.height()) / 2.0f - bounds.top; Canvas canvas = new Canvas(bitmap); canvas.drawText(text, x, y, paint); BitmapDescriptor icon = BitmapDescriptorFactory.fromBitmap(bitmap); return markerOptions.icon(icon); } 

}

0
source share

All Articles