My app have 1,5 thousand markers, showed throught marker clustering.
Actually it works fine with default markers, but i want do use vector bitmap and render markers with text (price of gas station), like this:
Before finishing rendering markers, occurs this exception: "Could not allocate dup blob fd."
I think it's some kind of memory overflow, but I do not know how to solve it. Does anyone have any idea how to solve this problem or have another suggestion of how to manage so many markers?
Note: I am already using marker clustering.
Note: This problem occurs only on some Motorola and LG devices. In most devices works fine. Some code:
public class OwnRendring extends DefaultClusterRenderer<MyItem> {
public OwnRendring(Context context, GoogleMap map, ClusterManager<MyItem> clusterManager) {
super(context, map, clusterManager);
}
protected void onBeforeClusterItemRendered(MyItem item, MarkerOptions markerOptions) {
markerOptions.snippet(item.getSnippet());
markerOptions.title(item.getTitle());
markerOptions.anchor(0.33f, 1f);
markerOptions.infoWindowAnchor(0.33f,0f);
int cor;
if (item.getPublico()) {
cor=cfgCorPostoPublico;
} else {
cor=cfgCorPostoPrivado;
}
String preço = item.getTitle().substring(item.getTitle().length() - 5);
if (Objects.equals(preço, "0,000")) { preço=""; }
Bitmap bitmap = createStoreMarker(preço, cor);
markerOptions.icon(BitmapDescriptorFactory.fromBitmap(bitmap));
super.onBeforeClusterItemRendered(item, markerOptions);
}
protected boolean shouldRenderAsCluster(Cluster cluster) {
// if markers < cfgClusterMin then not clustering
return cfgCluster && cluster.getSize() >= cfgClusterMin;
}
}
private Bitmap createStoreMarker(String text, int color) {
View markerLayout = getLayoutInflater().inflate(R.layout.custom_marker, null);
ImageView markerImage = (ImageView) markerLayout.findViewById(R.id.marker_image);
TextView markerRating = (TextView) markerLayout.findViewById(R.id.marker_text);
markerImage.setImageResource(R.drawable.pin_shadow);
markerImage.clearColorFilter();
markerImage.getDrawable().mutate().setColorFilter(color, PorterDuff.Mode.MULTIPLY );
markerRating.setText(text);
markerLayout.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED), View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
markerLayout.layout(0, 0, markerLayout.getMeasuredWidth(), markerLayout.getMeasuredHeight());
final Bitmap bitmap = Bitmap.createBitmap(markerLayout.getMeasuredWidth(), markerLayout.getMeasuredHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
markerLayout.draw(canvas);
return bitmap;
}