How can I use Picasso to add an icon in Marker?

I would like to use Picasso to extract a bitmap image to use as a marker icon, but I'm not sure how to do this. If I use Picasso to insert an image into an image, I know that I can use:

Picasso.with(MainActivity.this).load(URL).into(photo_imageview); 

Of course, this will not work if you pass it to .icon()

Is there an easy way to achieve this?

Thanks for watching this!

+5
android google-maps picasso
source share
2 answers

Picasso provides a generic Target interface that you can use to implement your own target image. In particular, you will want to override onBitmapLoaded to fill your token.

Below is a basic implementation.

 public class PicassoMarker implements Target { Marker mMarker; PicassoMarker(Marker marker) { mMarker = marker; } @Override public int hashCode() { return mMarker.hashCode(); } @Override public boolean equals(Object o) { if(o instanceof PicassoMarker) { Marker marker = ((PicassoMarker) o).mMarker; return mMarker.equals(marker); } else { return false; } } @Override public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) { mMarker.setIcon(BitmapDescriptorFactory.fromBitmap(bitmap)); } @Override public void onBitmapFailed(Drawable errorDrawable) { } @Override public void onPrepareLoad(Drawable placeHolderDrawable) { } } 

You would use it like this:

 marker = new PicassoMarker(myMarker); Picasso.with(MainActivity.this).load(URL).into(marker); 

Note Picasso only supports the weekly Target link passed to into . Therefore, a marker link must exist prior to loading the image to avoid garbage collection of callbacks.

+22
source share

Check out this sample Google code code, you can find the InfoWindowAdapter implementation to achieve it: googlemaps / android-samples

0
source share

All Articles