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.
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();
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With