Picasso image loading issue in GoogleMap.InfoWindowAdapter

前端 未结 2 2260
情歌与酒
情歌与酒 2020-12-15 10:25

I am using Google Maps Api and want to show an image inside InfoWindow when clicking of a Marker. I implemented it but there is a problem about Picasso. When I click a marke

2条回答
  •  庸人自扰
    2020-12-15 10:43

    What is working for me is this:

    Inside getInfoWindow(Marker marker):

    Picasso.with(getActivity())
                                .load(URL)
                                .error(R.drawable.my_loader)
                                .placeholder(R.drawable.my_loader)
                                .into(userPhoto, new MarkerCallback(marker,URL,userPhoto));
    

    Then create a class:

    public class MarkerCallback implements Callback {
    Marker marker=null;
    String URL;
    ImageView userPhoto;
    
    
    MarkerCallback(Marker marker, String URL, ImageView userPhoto) {
        this.marker=marker;
        this.URL = URL;
        this.userPhoto = userPhoto;
    }
    
    @Override
    public void onError() {
        //Log.e(getClass().getSimpleName(), "Error loading thumbnail!");
    }
    
    @Override
    public void onSuccess() {
        if (marker != null && marker.isInfoWindowShown()) {
            marker.hideInfoWindow();
    
            Picasso.with(getActivity())
                    .load(URL)                        
                    .into(userPhoto);
    
            marker.showInfoWindow();
        }
    }
    

    }

提交回复
热议问题