18

When I add new markers on the map programmatically using cluster manager it doesn't reflect the changes until I update the zoom in and zoom out.

I have seen lots of questions on stack overflow but that doesn't work for me,

So please tell me how to update the map without clearing the map.

Code:

 for (int i = 0; i < name.length; i++)
 { 
   Person_marker person_marker = new Person_marker(createRandLocation(latLng),
   name[i], getAddress(latLng), typedArray.getResourceId(i, -1), time[i], acuracy[i]);
   person_markerList.add(person_marker);
 } 
clusterManager.clearItems(); clusterManager.addItems(person_markerList);
Cœur
  • 37,241
  • 25
  • 195
  • 267
Edward Collins
  • 353
  • 3
  • 13
  • Please show what you have done so far. – Jamie Rees May 01 '15 at 08:46
  • @JamieRees for (int i = 0; i < name.length; i++) { Person_marker person_marker = new Person_marker(createRandLocation(latLng), name[i], getAddress(latLng), typedArray.getResourceId(i, -1), time[i], acuracy[i]); person_markerList.add(person_marker); } clusterManager.clearItems(); clusterManager.addItems(person_markerList); here is the code through which i am clearing the existing marker and adding new marker on map. – Edward Collins May 01 '15 at 08:54

1 Answers1

33

After adding all the markers, if you call clusterManager.cluster() it will draw what's been previsouly added.

Hope this helps

k3v1n4ud3
  • 2,904
  • 1
  • 15
  • 19
  • 2
    +1 Very nice, helped me! Where is that documented? Google's clustering demo does not use that, https://github.com/googlemaps/android-maps-utils/blob/master/demo/src/com/google/maps/android/utils/demo/ClusteringDemoActivity.java – Eduardo Oct 28 '15 at 17:09
  • 4
    You're right, I don't see it documented properly anywhere, but if you open the code of the ClusterManager (https://github.com/googlemaps/android-maps-utils/blob/master/library/src/com/google/maps/android/clustering/ClusterManager.java) and check the cluster method, the javadoc does say that you may wanna call it after adding new items. – k3v1n4ud3 Oct 29 '15 at 03:15