How to erase CustomMarker from google maps v2 android -
i have problem custom markers in google maps. i'll try explain best can.
i have markers, , did 1 asyntask, clusterize if necessary, returning linkedhashmap<point, arraylist<markeroptions>> clusters have clusters. each position represents cluster (it's possible have cluster 1 marker)
when got list, add clusters map:
here activity call clusterizer.
protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); map = ((supportmapfragment) getsupportfragmentmanager().findfragmentbyid(r.id.map)).getmap(); map.getuisettings().setmylocationbuttonenabled(true); cameraupdate camupd1 = cameraupdatefactory.newlatlngzoom(new latlng(41.40520680710329,2.191342011603923),map_zoom_level); map.animatecamera(camupd1); loadmarkers(); map.setoncamerachangelistener(new googlemap.oncamerachangelistener() { @override public void oncamerachange(cameraposition position) { if(position.zoom != oldzoom) { try { clusters = null; map.clear(); clusterizer.setcontext(getapplicationcontext()); clusters = clusterizer.clustermarkers(map, markers, interval); } catch (executionexception e) { e.printstacktrace(); } catch (interruptedexception e) { e.printstacktrace(); } } oldzoom = position.zoom; } }); } private void loadmarkers() { markers.add(new marker(41.40520680710229,2.191342011603823,"glorias1","centro comercial",true).getmarker()); markers.add(new marker(41.40520680710229+0.0005,2.191342011603823-0.0005,"glorias11","centro comercial",true).getmarker()); markers.add(new marker(41.40520680710229+0.0005,2.191342011603823+0.0005,"glorias111","centro comercial",true).getmarker()); markers.add(new marker(41.40520680710229-0.0005,2.191342011603823+0.0005,"glorias1111","centro comercial",true).getmarker()); markers.add(new marker(41.40520680710229-0.0005,2.191342011603823-0.0005,"glorias1111","centro comercial",true).getmarker()); } and, in asyntask after calculate clusters (it ok) postexecute method, this:
@override protected void onpostexecute( linkedhashmap<point, arraylist<markeroptions>> clusters) { map.clear(); for(point point: clusters.keyset()) { arraylist<markeroptions> markersforpoint = clusters.get(point); markeroptions mainmaker= markersforpoint.get(0); //if point (taken cluster, has more 1 markeroption, means has been clusterized, have printed //modified canvas contains number of markers clusterized) if(markersforpoint.size() > 1) { mainmaker.title(integer.tostring(markersforpoint.size())); bitmap.config conf = bitmap.config.argb_8888; bitmap bmp = bitmap.createbitmap(80, 80, conf); canvas canvas1 = new canvas(bmp); paint color = new paint(); color.settextsize(35); color.setcolor(color.black canvas1.drawbitmap(bitmapfactory.decoderesource(context.getresources(), r.drawable.pin), 0,0, color); canvas1.drawtext("",10,40,color); canvas1.drawtext(integer.tostring(markersforpoint.size()), 10, 40, color); mainmaker.icon(bitmapdescriptorfactory.frombitmap(bmp)); mainmaker.anchor(0.5f, 1); } map.addmarker(mainmaker); } } and here's problem...
if it's clustered there's no problem, shows ok, when made zoom in cluster list it's ok, marker isn't
thats hoow looks cluster when "clustered" , when suposed not clustered
how can fix it? clean map before add markers...
thanks all!
clustered:

not clustered

try adding:
color.settextalign(align.center); you may have tweak origin of paint centered in marker.
Comments
Post a Comment