Google Maps API v2 Android add shape drawable as marker -
i've been trying add shape drawable marker icon marker want add on map.
shape looks (res/drawable/blue_circle.xml):
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval" > <size android:width="15dp" android:height="15dp" /> <solid android:color="@color/blue" /> </shape>
and try add marker this:
markeroptions.icon(bitmapdescriptorfactory.fromresource(r.drawable.blue_circle));
apparently nullpointer exception.
must marker icon bitmap? allowed add shapes drawables marker icons? , if yes doing wrong?
create drawable marker (res/drawable/map_dot_red.xml):
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval" > <gradient android:angle="90" android:endcolor="#f58383" android:startcolor="#ee6464" /> <stroke android:width="1dp" android:color="#a13939" /> </shape>
create bitmap drawable:
int px = getresources().getdimensionpixelsize(r.dimen.map_dot_marker_size); mdotmarkerbitmap = bitmap.createbitmap(px, px, bitmap.config.argb_8888); canvas canvas = new canvas(mdotmarkerbitmap); drawable shape = getresources().getdrawable(r.drawable.map_dot_red); shape.setbounds(0, 0, mdotmarkerbitmap.getwidth(), mdotmarkerbitmap.getheight()); shape.draw(canvas);
create marker, using bitmap:
marker marker = mmap.addmarker(new markeroptions() .position(point) .anchor(.5f, .5f) .icon(bitmapdescriptorfactory.frombitmap(mdotmarkerbitmap)));
set size of marker in dimens (res/values/dimens.xml):
<resources> <dimen name="map_dot_marker_size">12dp</dimen> </resources>
Comments
Post a Comment