java - Custom Map Marker -
i have map view markers. i'm wanting know if can add couple of other string values markers such phone number , website. don't want these show in info window when marker tapped. when info window tapped goes detail activity selected marker. marker title , snippet passed extras detail activity , i'd pass 2 additional strings extras well.
here create markers:
for(int = 0; < lat.length; i++) { marker marker = map.addmarker(new markeroptions() .position(new latlng(lat[i], lon[i])) .title(market[i]) .snippet(address[i]) .icon(bitmapdescriptorfactory.defaultmarker(bitmapdescriptorfactory.hue_azure))); list.add(marker); }
and here start detail activity.
map.setoninfowindowclicklistener(new googlemap.oninfowindowclicklistener() { @override public void oninfowindowclick(marker marker) { // show details intent intent = new intent(getactivity(), farmmarketdetails.class); intent.putextra("selectedtitle", marker.gettitle()); intent.putextra("selectedaddress", marker.getsnippet()); startactivity(intent); } });
i created custom marker following code please check whether it's helpful you
marker marki=map.addmarker(new markeroptions() .icon(bitmapdescriptorfactory.frombitmap(writetextondrawable(r.drawable.my, ""))) .position((new latlng(latitude,longitude)))) ;
method customizing marker
private bitmap writetextondrawable(int drawableid, string text) { bitmap bm = bitmapfactory.decoderesource(getresources(), drawableid) .copy(bitmap.config.argb_8888, true); typeface tf = typeface.create("helvetica", typeface.bold); paint paint = new paint(); paint.setcolor(color.blue); paint.settypeface(tf); paint.settextalign(align.center); paint.settextsize(converttopixels(context,11)); rect textrect = new rect(); paint.gettextbounds(text, 0, text.length(), textrect); canvas canvas = new canvas(bm); //if text bigger canvas , reduce font size if(textrect.width() >= (canvas.getwidth() - 4)) //the padding on either sides considered 4, appropriately fit in text paint.settextsize(converttopixels(context,7)); //scaling needs used different dpi's //calculate positions int xpos = (canvas.getwidth() / 2) - 2; //-2 regulating x position offset //"- ((paint.descent() + paint.ascent()) / 2)" distance baseline center. int ypos = (int) ((canvas.getheight() / 2) - ((paint.descent() + paint.ascent()) / 2)) ; canvas.drawtext(text, xpos, ypos, paint); return bm; } public static int converttopixels(context context, int ndp) { final float conversionscale = context.getresources().getdisplaymetrics().density; return (int) ((ndp * conversionscale) + 0.5f) ; }
Comments
Post a Comment