Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change marker in map clustering android

I am using Map Utils library for clustering on map. now, i want change default markers which are showing in map like below:

enter image description here

you can see markers in green circle. i want to change that. i already implemented this. but dont know how to change this. if you anyone know then help to solve this.

Code:

@Override
    protected void startDemo() {
        getMap().moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(51.503186, -0.126446), 10));

        mClusterManager = new ClusterManager<MyItem>(this, getMap());
        getMap().setOnCameraChangeListener(mClusterManager);

        try {
            readItems();
        } catch (JSONException e) {
            Toast.makeText(this, "Problem reading list of markers.", Toast.LENGTH_LONG).show();
        }
    }

    private void readItems() throws JSONException {
        InputStream inputStream = getResources().openRawResource(R.raw.radar_search);
        List<MyItem> items = new MyItemReader().read(inputStream);
        mClusterManager.addItems(items);
    }
like image 805
Sagar Maiyad Avatar asked Feb 12 '15 05:02

Sagar Maiyad


Video Answer


1 Answers

You should implement onBeforeClusterItemRendered and make your changes by making a custom Renderer class :

 public class MarkerClusterRenderer extends DefaultClusterRenderer<MyItem> {

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

    @Override
    protected void onBeforeClusterItemRendered(MyItem item, MarkerOptions markerOptions) {
        // use this to make your change to the marker option 
        // for the marker before it gets render on the map
        markerOptions.icon(BitmapDescriptorFactory.
                fromResource(R.drawable.your_custom_marker));
    }
}

and Don't forget to add your custom Renderer to your Cluster Manager

 mClusterManager.setRenderer(new MarkerClusterRenderer(this, mMap, mClusterManager));
like image 158
MFQ Avatar answered Oct 02 '22 12:10

MFQ