我正在使用 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模板网!
为什么在 Eclipse 的 SDK 中选择 Android API 而不是 Why would you choose Android API over Google APIs in the SDK on Eclipse?(为什么在 Eclipse 的 SDK 中选择 Android API 而不是 Google API?)
Couchbase 存储桶身份验证错误Couchbase Bucket authentication error(Couchbase 存储桶身份验证错误)
admob 6.2.1 空指针异常admob 6.2.1 nullpointer exception(admob 6.2.1 空指针异常)
如何在 IntelliJ IDEA 中设置 SDK?How to setup SDK in IntelliJ IDEA?(如何在 IntelliJ IDEA 中设置 SDK?)
eclipse 无法检测到我的手机进行试运行My phone cannot be detected in eclipse to test run(eclipse 无法检测到我的手机进行试运行)
android SDK 中缺少 platform-toolsaapt.exe 目录platform-toolsaapt.exe directory missing in android SDK(android SDK 中缺少 platform-toolsaapt.exe 目录)