問題描述
我正在使用 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.
這篇關于更新單項 GoolgeMap Cluster的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!