Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Refresh markers on cluster manager

while the user navigates the map, the app will get new locations for he to see. But the map is not refreshing with the new markers.

After receiving a JSON with the places, this method put them on the map.

private void setMarkers(JSONObject response) {

    mClusterManager.clearItems();

    try {
        JSONArray venues = response.getJSONArray("venues");

        for (int i = 0; i < venues.length(); i++) {
            Venue venue = new Gson().fromJson(venues.getJSONObject(i).toString(), Venue.class);
            MarkerItem marker = new MarkerItem(venue.getLat(), venue.getLng(), venue, R.drawable.pin_quente);
            mClusterManager.addItem(marker);
        }

    } catch (JSONException e) {
        e.printStackTrace();
    }
}

The first request put them ok, but the second do nothing.

like image 299
Bruno Pinto Avatar asked Dec 06 '22 00:12

Bruno Pinto


1 Answers

Use:

mClusterManager.cluster();

After adding markers.

private void setMarkers(JSONObject response) {

    mClusterManager.clearItems();

    try {
        JSONArray venues = response.getJSONArray("venues");

        for (int i = 0; i < venues.length(); i++) {
            Venue venue = new Gson().fromJson(venues.getJSONObject(i).toString(), Venue.class);
            MarkerItem marker = new MarkerItem(venue.getLat(), venue.getLng(), venue, R.drawable.pin_quente);
            mClusterManager.addItem(marker);
        }

        mClusterManager.cluster(); 

    } catch (JSONException e) {
        e.printStackTrace();
    }
}
like image 171
XYZ Comunicación Avatar answered Dec 10 '22 11:12

XYZ Comunicación