如果我在onMapReady
内添加我的clusterItem,如下所示
@Override
public void onMapReady(GoogleMap googleMap) {
Log.d("CustomMapFragment","onMapReady");
map = googleMap;
map.getUiSettings().setAllGesturesEnabled(true);
map.getUiSettings().setCompassEnabled(true);
map.getUiSettings().setZoomGesturesEnabled(true);
map.getUiSettings().setZoomControlsEnabled(true);
mClusterManager.addItem(new MyMarker(23.748865, 90.411655, "a", new Resultset("112113","dsd")));
mClusterManager.addItem(new MyMarker(23.749049, 90.411382, "b", new Resultset("112113","ddfdsd")));
mClusterManager.addItem(new MyMarker(23.749129, 90.411088, "c", new Resultset("11211dsd3","dsd")));
mClusterManager.addItem(new MyMarker(23.749241, 90.41068, "d", new Resultset("112113","fgdsd")));
mClusterManager.addItem(new MyMarker(23.749183, 90.410257, "e", new Resultset("112113","qwdsd")));
}
如果我在onMapReady
中添加一些群集,则按预期方式进行群集工作。但我定期调用一个Web服务,它将集群项添加到地图
UIUpdater mUIUpdater = new UIUpdater(new Runnable() {
@Override
public void run() {
//running a web service
mClusterManager.addItem(new MyMarker(lat, longitude, memberListModel.get(i).getFirstName()+" "+ memberListModel.get(i).getLastName(), memberListModel.get(i)));
}
}
在调用周期性任务后,标记会添加到地图中,但是如果我放大或缩小地图,标记最初是不可见的,则没有聚类效果,标记是可见的,但没有聚类效果。
我添加了以下依赖项
compile "com.google.android.gms:play-services-maps:9.4.0"
compile "com.google.android.gms:play-services-location:9.4.0"
compile 'com.google.maps.android:android-maps-utils:0.4+'
在片段的onResume
中我启动了周期性任务运行器并在onPause
中停止
@Override
public void onResume() {
super.onResume();
mUIUpdater.startUpdates();
}
@Override
public void onPause() {
super.onPause();
mUIUpdater.stopUpdates();
}
如何添加群集项以在定期任务运行器内进行映射?
答案 0 :(得分:2)
添加群集项后,您应该调用以下方法。
mClusterManager.clearItems();
mClusterManager.cluster();
答案 1 :(得分:2)
public class TheClusterItem implements ClusterItem {
...
}
TheClusterItem item = new TheClusterItem(...);
mClusterManager.addItem(item); // or list of items
mClusterManager.cluster();
添加项目并调用群集方法后,将在适当的区域更新群集。