更新单项 GoolgeMap Cluster

我正在使用 this libray 在 Android 中集群 GoogleMap.我的问题是如何更新我昨天通过谷歌浏览的单个项目,但没有解释更新单个项目的答案.我在我的项目中使用 websocket,所以我需要更新从 websocket 接收到的项目数据.下面看看我的实现.

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.

我的概念是做mClusterManager.remove(项目)mClusterManager.add(item) + mClusterManager.cluster() 每当我从 websocket 接收数据.

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

和 hasmap 在添加到集群时识别循环中的对象,例如:hashmap.put(_id,mClusterItem[i]);

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

现在,每当收到 websocket 数据时,我都会这样做,

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();
    }

但是,上面的代码在收到第一个数据时首先工作,然后从第二次开始,它将继续添加标记并且无法删除,这意味着找不到 mClusterManager.remove(hasmap.get(_id)).而 appClusterItem[0] 是因为我不能使用 hashmap.get(_id);在上述情况下,因为它给出了预期的错误变量.无论如何要删除相同的对象并在该位置添加对象??

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??

推荐答案

我也尝试通过 mClusterManager.remove 从集群中删除标记,但遇到了一些问题.因此,就我而言,当我收到数据更改时,我会这样做:我删除了需要从列表中删除的项目,使用 mClusterManager.clearItems(); 清除集群上的所有标记并将新数据放入集群.

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.

相关文章