Load image with Glide to Google Maps Marker
Decided with recreate bitmap
Glide.with(getBaseActivity())
.load(place.getIconUrl())
.asBitmap()
.dontTransform()
.into(new SimpleTarget<Bitmap>() {
@Override
public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {
final float scale = getContext().getResources().getDisplayMetrics().density;
int pixels = (int) (50 * scale + 0.5f);
Bitmap bitmap = Bitmap.createScaledBitmap(resource, pixels, pixels, true);
markerImageView.setImageBitmap(bitmap);
addMarker(place.getLatLng());
}
@Override
public void onLoadFailed(Exception e, Drawable errorDrawable) {
markerImageView.setImageResource(R.drawable.ic_marker_default_logo);
addMarker(place.getLatLng());
}
});
Glide.with(this).load("url").listener(object : RequestListener<Drawable> {
override fun onLoadFailed(e: GlideException?, model: Any?, target: Target<Drawable>?, isFirstResource: Boolean): Boolean {
return true
}
override fun onResourceReady(resource: Drawable?, model: Any?, target: Target<Drawable>?, dataSource: DataSource?, isFirstResource: Boolean): Boolean {
callmethod(resource) //pass drawable to your method and set the drawable for marker there
imageSource=resource
return true
}
})
using
BitmapDescriptor icon = BitmapDescriptorFactory.fromBitmap(convertToBitmap(d,100,100));
MarkerOptions markerOptions = new MarkerOptions()
.position(latLng).icon(icon)
.title(getString(titleResId))
.draggable(true);
also for getting the bitmap from drawable
public Bitmap convertToBitmap(Drawable drawable, int widthPixels, int heightPixels) {
Bitmap mutableBitmap = Bitmap.createBitmap(widthPixels, heightPixels, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(mutableBitmap);
drawable.setBounds(0, 0, widthPixels, heightPixels);
drawable.draw(canvas);
return mutableBitmap;
}
or you can use just
public Bitmap getBitmapFromURL(String strURL) {
try {
URL url = new URL(strURL);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoInput(true);
connection.connect();
InputStream input = connection.getInputStream();
Bitmap myBitmap = BitmapFactory.decodeStream(input);
return myBitmap;
} catch (IOException e) {
e.printStackTrace();
return null;
}
}