android - How to add a ring around the custom image marker pointing down on the map without using drawable file -
private googlemap mmap; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_maps); // obtain supportmapfragment , notified when map ready used. supportmapfragment mapfragment = (supportmapfragment) getsupportfragmentmanager() .findfragmentbyid(r.id.map); mapfragment.getmapasync(this); } /** * manipulates map once available. * callback triggered when map ready used. * can add markers or lines, add listeners or move camera. in case, * add marker near sydney, australia. * if google play services not installed on device, user prompted install * inside supportmapfragment. method triggered once user has * installed google play services , returned app. */ @override public void onmapready(googlemap googlemap) { mmap = googlemap; bitmap scaled = bitmap.createscaledbitmap(bitmapfactory.decoderesource(getresources(), r.drawable.ab), 120, 120, true); bitmap image=getcircularbitmap(scaled);
// modify canvas // canvas1.drawbitmap(scaled, 0,0, color);
// add marker in sydney , move camera latlng sydney = new latlng(-34, 151); markeroptions markeroptions = new markeroptions(); markeroptions.position(sydney); markeroptions.icon(bitmapdescriptorfactory.frombitmap(image)); mmap.addmarker(markeroptions); mmap.movecamera(cameraupdatefactory.newlatlng(sydney)); } public bitmap getcircularbitmap(bitmap bitmap) { bitmap output; if (bitmap.getwidth() > bitmap.getheight()) { output = bitmap.createbitmap(bitmap.getheight(), bitmap.getheight(), bitmap.config.argb_8888); } else { output = bitmap.createbitmap(bitmap.getwidth(), bitmap.getwidth(), bitmap.config.argb_8888); } canvas canvas = new canvas(output); final int color = 0xff424242; final paint paint = new paint(); final rect rect = new rect(0, 0, bitmap.getwidth(), bitmap.getheight()); float r = 0; if (bitmap.getwidth() > bitmap.getheight()) { r = bitmap.getheight() / 2; } else { r = bitmap.getwidth() / 2; } paint.setantialias(true); canvas.drawargb(0, 0, 0, 0); paint.setcolor(color); canvas.drawcircle(r, r, r, paint); paint.setxfermode(new porterduffxfermode(porterduff.mode.src_in)); canvas.drawbitmap(bitmap, rect, rect, paint); return output
developers required use drawables passed thru bitmapdescriptorfactory
indicated in documentation. ring around image should part of image itself, if multi-colored (like on image provided), can use multiple templates markers.
hope helps!
Comments
Post a Comment