1

Is it possible to add a marker on an image using any image library in android ?

so far I have loaded an image into ImageView using picasso and all the solutions I have googled involved adding marker in Google maps!

Just Like the marker center in the image

Community
  • 1
  • 1

1 Answers1

2

Picasso provides a generic Target interface you can use to implement your own image destination. Specifically, you will want to override onBitmapLoaded to populate your marker.

A basic implementation is given below.

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);
aldok
  • 17,295
  • 5
  • 53
  • 64