我的自定义标记存在问题,我想使其成为群集标记(一组制造商),但是它不起作用,我在Google地图中找到了所有标记,所以即使我使用了clusterManager处理这种情况我无法获得想要的结果:
public MyClusterManagerRenderer(Context context, GoogleMap googleMap,
ClusterManager<ClusterMarker> clusterManager) {//initialize
}
@Override
protected void onBeforeClusterItemRendered(ClusterMarker item, MarkerOptions markerOptions) {
imageView.setImageResource(item.getIconPicture());
Bitmap icon = iconGenerator.makeIcon();
markerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon)).title(item.getTitle());
}
@Override
protected void onBeforeClusterRendered(Cluster<ClusterMarker> cluster,
MarkerOptions markerOptions) {
iconGenerator.setBackground(null);
Bitmap icon = iconGenerator.makeIcon(String.valueOf(cluster
.getSize()));
markerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon));
}
@Override
protected boolean shouldRenderAsCluster(Cluster cluster) {
return false;
}
在我的GoogleMapsFragment中,我有这种绘制标记的方法:
private void addMapMarkers(List<Place> places){ if(places != null && !places.isEmpty() && googleMap != null) { mClusterManager = new ClusterManager<ClusterMarker>(getActivity(), googleMap); mClusterManagerRenderer = new MyClusterManagerRenderer(getActivity(),googleMap,mClusterManager); mClusterManager.setRenderer(mClusterManagerRenderer); for(Place p: places){ try{ ClusterMarker newClusterMarker = null; if(p != null) { newClusterMarker = new ClusterMarker(new LatLng(Double.parseDouble(p.getLocation().getLat()),
Double.parseDouble(p.getLocation()。getLng())),p.getName(),代码段, 化身,p); }
if (newClusterMarker != null) { mClusterManager.addItem(newClusterMarker); mClusterMarkers.add(newClusterMarker); } }catch (NullPointerException e){ Log.e(TAG, "7 : "+"addMapMarkers: NullPointerException: " + e.getMessage() ); } } mClusterManager.cluster(); googleMap.moveCamera(prepareCameraForMap(places)); } else Log.e(TAG, "9 : Markers not drawed googleMap is null"); }
答案 0 :(得分:0)
我删除了此方法:
来自shouldRenderAsCluster(Cluster cluster)
的{{1}},我的代码运行正常。