Show text on polygon android Google map v2 -
i using polygons on map , want have text on them. there possible way this? tried put simple text on map point didn't make it.
private void addpolygon(region reg) { polylineoptions polylineoptions = new polylineoptions(); arraylist<latlng> coordlist=reg.getallpoints(); coordlist.add(coordlist.get(0)); int regcolor = reg.getcolor(); string regname = reg.getname(); //want put name on region polylineoptions.addall(coordlist); polylineoptions .width(5) .color(color.black); if (regcolor != 0) polylineoptions .color(regcolor); map.addpolyline(polylineoptions); //text on shape? }
you can create marker custom icon, , draw text on icon. can use method this:
public marker addtext(final context context, final googlemap map, final latlng location, final string text, final int padding, final int fontsize) { marker marker = null; if (context == null || map == null || location == null || text == null || fontsize <= 0) { return marker; } final textview textview = new textview(context); textview.settext(text); textview.settextsize(fontsize); final paint painttext = textview.getpaint(); final rect boundstext = new rect(); painttext.gettextbounds(text, 0, textview.length(), boundstext); painttext.settextalign(align.center); final bitmap.config conf = bitmap.config.argb_8888; final bitmap bmptext = bitmap.createbitmap(boundstext.width() + 2 * padding, boundstext.height() + 2 * padding, conf); final canvas canvastext = new canvas(bmptext); painttext.setcolor(color.black); canvastext.drawtext(text, canvastext.getwidth() / 2, canvastext.getheight() - padding - boundstext.bottom, painttext); final markeroptions markeroptions = new markeroptions() .position(location) .icon(bitmapdescriptorfactory.frombitmap(bmptext)) .anchor(0.5f, 1); marker = map.addmarker(markeroptions); return marker; } you need set location latlng of marker , have calculate region (for example first point of geometry, last point, random point, centroid, ...).
also, take account drawing lot of markers have negative effect in performance.
Comments
Post a Comment