1

Hello im using google map api v2, and i have created custom marker class named FirmaMarker, and i want to display it with image from URL that im getting from database.
Im using Picasso to load image, but problem is that marker is created before image is fetched so i just get markers created without image, and user need to reopen activity few times so images actually get fetched and appear.

Here is custom marker renderer class

public class FirmaRenderer extends DefaultClusterRenderer<FirmaMarker> {

private final IconGenerator iconGenerator;
private final ImageView slika;
private final int width;
private final int height;
private Marker marker;
private MarkerOptions mOptions;
private Context context;

public FirmaRenderer(Context context, GoogleMap map, ClusterManager<FirmaMarker> clusterManager, int width, int height) {
    super(context, map, clusterManager);
    this.width = width;
    this.height = height;
    this.context = context;

    iconGenerator = new IconGenerator(context.getApplicationContext());
    slika = new ImageView(context.getApplicationContext());
    slika.setLayoutParams(new ViewGroup.LayoutParams(width,height));
    slika.setPadding(5,5,5,5);
    iconGenerator.setContentView(slika);
}
@Override
protected void onBeforeClusterItemRendered(FirmaMarker item, MarkerOptions markerOptions) {
    Picasso.get().load(item.getSlika()).fetch();
    Bitmap icon = iconGenerator.makeIcon();
    markerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon)).title(item.getTitle());
    Picasso.get().load(item.getSlika()).into(slika);
}

@Override
protected boolean shouldRenderAsCluster(Cluster<FirmaMarker> cluster) {
    return false;
}}

And how i create markers in main activity

        if(Map != null)
    {
        if(clusterManager == null)
        {
            clusterManager = new ClusterManager<FirmaMarker>(this,Map);
        }
        if(firmaRenderer == null)
        {
            firmaRenderer= new FirmaRenderer(
                    this,
                    Map,
                    clusterManager,
                    160,
                    100
            );
            clusterManager.setRenderer(firmaRenderer);
        }
        for(int i=0;i<FirmaID.size();i++)
        {
            FirmaMarker marker = new FirmaMarker(
                    new LatLng(Double.parseDouble(Sirina.get(i)), Double.parseDouble(Duzina.get(i))),
                    Naziv.get(i),
                    "Притисните за више информација",
                    LinkSlike.get(i),
                    Integer.parseInt(FirmaID.get(i))
            );
            clusterManager.addItem(marker);
            Markeri.add(marker);
        }
        clusterManager.cluster();
    }
  • 1
    You'll have to use the Picasso callback mechanism on the `into` method and do something to update the marker image (or info window) if applicable as in here: https://stackoverflow.com/a/36335163/2711811. Alternatively use same callback to initiate the add marker logic - just add the marker _after_ the image is loaded and callback invoked. –  Nov 04 '19 at 21:51
  • What should i do in callback onSuccess, markers are created in Map class, but picasso callback is located in FirmaRenderer class, i cannot add markers from there or anything. – Аца Русија Nov 05 '19 at 19:07
  • Are you still having this issue @АцаРусија ? – evan Nov 08 '19 at 13:19
  • Yeah, i dont know what to do now – Аца Русија Nov 08 '19 at 21:34
  • Alright! Let me have a look at this later, will get back to you. – evan Nov 12 '19 at 13:19
  • Could you please post all your code from both activities so that we can reproduce this on our end? – evan Nov 13 '19 at 13:11
  • Here is the detailed answer including code snippet https://stackoverflow.com/a/61929527/8663316 – Faizan Haidar Khan May 21 '20 at 07:36

0 Answers0