android中集群组的自定义图标
作者:互联网
我想用我的可绘制图标更改defult群集组图标.
请检查我的集群程序代码.
MyClusterRenderer.java
public class MyClusterRenderer extends DefaultClusterRenderer<MyItem> {
public MyClusterRenderer(Context context, GoogleMap map,
ClusterManager<MyItem> clusterManager) {
super(context, map, clusterManager);
}
@Override
protected void onBeforeClusterItemRendered(MyItem item, MarkerOptions markerOptions) {
super.onBeforeClusterItemRendered(item, markerOptions);
markerOptions.title("").icon(BitmapDescriptorFactory.fromResource(R.mipmap.location_both));// for marker
}
@Override
protected void onClusterItemRendered(final MyItem clusterItem, Marker marker) {
super.onClusterItemRendered(clusterItem, marker);
}
}
安装片段中的代码
googleMap.clear();
mClusterManager = new ClusterManager<MyItem>(getActivity(), googleMap);
googleMap.setOnMarkerClickListener(mClusterManager);
googleMap.setOnCameraChangeListener(mClusterManager);
readItems();
mClusterManager.setRenderer(new MyClusterRenderer(getActivity(), googleMap, mClusterManager));
解决方法:
尝试在onBeforeClusterRendered方法而不是onBeforeClusterItemRendered方法中更改Cluster图标:
@Override
protected void onBeforeClusterRendered(Cluster<MyItem> cluster, MarkerOptions markerOptions) {
markerOptions.icon(BitmapDescriptorFactory.fromResource(R.mipmap.location_both));
}
标签:google-maps,marker,markerclusterer,android 来源: https://codeday.me/bug/20191026/1933469.html