Android Google Maps API String inside the Marker Icon

前端 未结 3 1329
被撕碎了的回忆
被撕碎了的回忆 2021-01-21 08:46

Is there a way I can put a value of a String inside the Marker\'s icon on Google Maps API 2.0? Like this image

3条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-21 09:21

    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)));
    

提交回复
热议问题