【发布时间】:2014-03-17 08:12:32
【问题描述】:
对不起我的英语
我尝试了ClusterManager<?>.getMarkerCollection().getMarkers() 方法,但它返回空集合。
我在我的应用程序中使用Google Maps Utility Library。每次屏幕旋转后,我都会创建AsynkTask,并在后台线程中从数据库读取数据并将项目添加到ClusterManager:
cursor.moveToFirst();
while (!cursor.isAfterLast()) {
SomeData row = readSomeDataRow(cursor);
clusterManager.addItem(new ClusterItemImpl(row));
cursor.moveToNext();
}
当AsyncTask 完成工作时(即在主线程中),我尝试从ClusterManager 中获取所有标记:
clusterManager.cluster();
// cluster manager returns empty collection \|/
markers = clusterManager.getMarkerCollection().getMarkers();
但 ClusterManager 返回空集合。
可能在我调用getMarkers() ClusterManager 的那一刻,但没有在地图上放置标记,稍后会做(可能在后台线程中)。如果是这样,那我怎样才能抓住那一刻?
【问题讨论】:
-
您找到解决问题的方法了吗?
-
clusterManager.getClusterMarkerCollection().getMarkers();仅当标记处于缩放级别时才返回标记,以便我们可以在地图中看到它们
-
由于 ClusterManager 方法 cluster() 创建并调用 ClusterManager.ClusterTask() AsyncTask,因此您在调用 cluster() 后尝试正确获取标记是错误的。似乎当 ClusterManager.ClusterTask 完成时,它会调用 ClusterRenderer 对象上的 onClustersChanged() 方法。
标签: android google-maps-android-api-2 marker markerclusterer