Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Update single item GoolgeMap Cluster

I am using this libray to cluster GoogleMap in Android. My question is how can I update the single item I have gone through google from yesterday and no answers are there that explains updating single item. I am using websocket in my project so I need to update the data of item that were received from websocket. Look my implementation below.

My concept is doing mClusterManager.remove(item) mClusterManager.add(item) + mClusterManager.cluster() whenever I receive data from websocket.

and hasmap to identify the object on loop while adding to cluseter like : hashmap.put(_id,mClusterItem[i]);

Now, Whenever on websocket data is received I do,

    onDataReceive(String _id,String name, double latlng, ....){
    mClusterManager.remove(hashmap.get(_id));

   appClusterItem[0] = new AppClusterItem(.....);
    mClusterManager.add(appClusterItem[0])  // Here how can I add item 
    mClusterManager.cluster();
    }

However the above code works first when first data receives, then from second time it will just keep adding the marker and fails to remove that means mClusterManager.remove(hasmap.get(_id)) is not found. And appClusterItem[0] is because I cannot use hashmap.get(_id); on above case bacause it give error variable expected. Anyway to remove the same object and add object on that place??

like image 438
Queendevelopers Avatar asked Nov 21 '18 05:11

Queendevelopers


2 Answers

I also tried to remove marker from cluster via mClusterManager.remove and have some problem with it. So in my case, when I received data changes I make this: I remove item that i need to remove from my list, clear all markers on cluster with mClusterManager.clearItems(); and put fresh data to cluster.

like image 164
Vadim Eksler Avatar answered Nov 07 '22 04:11

Vadim Eksler


ClusterManager is having removeItem() defined as below

public void removeItem(T item) {
        mAlgorithmLock.writeLock().lock();
        try {
            mAlgorithm.removeItem(item);
        } finally {
            mAlgorithmLock.writeLock().unlock();
        }
}

You need to pass custom Item object that might be extended from ClusterItem. Check the method documentation from library class defined here.

like image 42
karan Avatar answered Nov 07 '22 02:11

karan