I have this series of xml-drawables in particular drawable folders, for example in drawable-mpdi:
<?xml version="1.0" encoding="utf-8"?>
<bitmap
xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/m0_48px"
/>
drawable-hdpi differs only with src pointing to m0_72px and so on.
And I want to let android decide what image resolution will use in marker. If I do this in this way:
int imageRes = c.getResources().getIdentifier("drawable/m0",
null, c.getPackageName());
Marker marker = m.addMarker(new MarkerOptions()
.position(new LatLng(s.lat, s.lon))
.icon(BitmapDescriptorFactory.fromResource(imageRes))
.anchor(0.5f, 1f));
I get some resource ID in imagesRes, but BitmapDescriptorFactory won't accept this.
If I do it in this way:
int imageRes = c.getResources().getIdentifier("drawable/m0",
null, c.getPackageName());
Bitmap bitmap = BitmapFactory.decodeResource(c.getResources(), imageResource);
Marker marker = m.addMarker(new MarkerOptions()
.position(new LatLng(s.lat, s.lon))
.icon(BitmapDescriptorFactory.fromResource(imageRes))
.anchor(0.5f, 1f));
I get null in bitmap var.
This question Set Image from drawable as marker in Google Map version 2 and especially this comment
Well, you can - you just need to paint it into a Canvas first (drawable.draw(canvas)), then dump the Canvas to a Bitmap. – Chris Broadfoot
lead me nowhere I'm not able to replicate mentioned procedure...
Please, any help welcome!