Osmdroid insertion text inside the marker

How can I insert text inside an osmdroid marker? Suppose I need to place several markers on a map, and each marker must have a number inside it. enter image description hereHow can i do this? I try the #setTitle()method, but it puts the text in a balloon.

Update:

for(int i = 0; i < orders.size(); i++) {
    mOrderPoint = orders.get(i).getStart();
    final Order order = orders.get(i);
    Marker orderMarker = new Marker(mMap);
    orderMarker.setIcon(ContextCompat.getDrawable(mContext,R.drawable.order_pin));
    orderMarker.setPosition(mOrderPoint);
}
+4
source share
2 answers

This method extracts resources from your resources, draws text above it and returns a new one. All you have to do is give it the resource ID of your bubble and the text you want on top. You can then pass the returned drawing wherever you want.

public BitmapDrawable writeOnDrawable(int drawableId, String text){

        Bitmap bm = BitmapFactory.decodeResource(getResources(), drawableId).copy(Bitmap.Config.ARGB_8888, true);

        Paint paint = new Paint(); 
        paint.setStyle(Style.FILL);  
        paint.setColor(Color.BLACK); 
        paint.setTextSize(20); 

        Canvas canvas = new Canvas(bm);
        canvas.drawText(text, 0, bm.getHeight()/2, paint);

        return new BitmapDrawable(bm);
    }

Note:

To maintain density, you will need this constructor

BitmapDrawable (Resources res, Bitmap bitmap)

, , -

    return new BitmapDrawable(context.getResources(), bm);

.

+6
+1

All Articles