Tenho aproximadamente 1,5 mil marcadores em um mapa que estão sendo mostrados através de clusters para não sobrecarregar o aplicativo. estes marcadores atualmente são mostrados como BitmapDescriptorFactory.defaultMarker()
No entanto, quando modifico o código para cada ponto mostrar um bitmap personalizado com valores sobre os marcadores, apenas alguns poucos aparelhos apresentam este erro, entre eles LG K10 LTE e Alguns Motorolas. Na maioria dos aparelhos funciona normalmente.
Quando utilizo esta função, antes de terminar de renderizar todos os 1500 marcadores, trava com o seguinte erro:
"Could not allocate dup blob fd."
Em pesquisas sobre este erro, me parece que trata-se de um estouro de memória e que devo armazenar estes marcadores em cache LRU, mas não estou conseguindo fazer isso em conjunto com os clusters.
Alguém já passou por isso ou tem alguma ideia/sugestão para solucionar este problema ?
Segue abaixo o trecho do código renderizador dos bitmaps:
public class OwnRendring extends DefaultClusterRenderer<MyItem> {
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 = (item.getPublico() ? cfgCorPostoPublico : cfgCorPostoPrivado);
String preço = item.getTitle().substring(item.getTitle().length() - 5);
markerOptions.icon(BitmapDescriptorFactory.fromBitmap(createMarker(preço, cor)));
super.onBeforeClusterItemRendered(item, markerOptions);
}
protected boolean shouldRenderAsCluster(Cluster cluster) {
return cfgCluster && cluster.getSize() >= cfgClusterMin;
}
}
@Override
public void onCameraIdle() {mClusterManager.cluster();}
private Bitmap createMarker(String text, int color) {
View markerLayout = getLayoutInflater().inflate(R.layout.custom_marker, null);
ImageView markerImage = markerLayout.findViewById(R.id.marker_image);
TextView markerRating = 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;
}