Update single item GoolgeMap Cluster

时间秒杀一切 提交于 2019-12-01 17:18:58

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.

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.

Have you tried to recluster when removing and recluster again when adding? I think I solve mine with that. Your code would be:

 onDataReceive(String _id,String name, double latlng, ....){
mClusterManager.remove(hashmap.get(_id));
mClusterManager.cluster();                   //add this line
appClusterItem[0] = new AppClusterItem(.....);
mClusterManager.add(appClusterItem[0])  // Here how can I add item 
mClusterManager.cluster();                   //leave this one here
hashmap.remove(_id);
hashmap.put(_id,mClusterItem[0]); //also don't forguet to update your hashmap
}

let me know if it worked for you!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!