Israel Neves Israel Neves - 6 months ago 21
Android Question

Android Google Maps API String inside the Marker Icon

Is there someway i can put a value of a string inside the icon on Google Maps API 2.0 ?

like this img this img
like

map.addMarker(new MarkerOptions()
.position(POSITION)
.title("Your title")
.icon(HERE PUT MY VAR STRING)
);

Answer

You can custom icon with your text:

Bitmap.Config conf = Bitmap.Config.ARGB_8888;
Bitmap bmp = Bitmap.createBitmap(80, 80, conf);
Canvas canvas = new Canvas(bmp);

// paint defines the text color, stroke width and size
Paint color = new Paint();
color.setTextSize(35);
color.setColor(Color.BLACK);

// modify canvas
canvas.drawText(YOUR_STRING, 30, 40, color);

// add marker to Map
mMap.addMarker(new MarkerOptions().position(USER_POSITION)
    .icon(BitmapDescriptorFactory.fromBitmap(bmp)));
Comments