Android Google Maps API String inside the Marker Icon

被刻印的时光 ゝ 提交于 2019-12-01 20:54:47

You can use the Google Maps API Utility Library and customize you markers using bubble icons:

IconGenerator iconFactory = new IconGenerator(this);

MarkerOptions markerOptions = new MarkerOptions().
    icon(BitmapDescriptorFactory.fromBitmap(iconFactory.makeIcon("Your text"))).
    position(new LatLng(-33.8696, 151.2094)).
    anchor(iconFactory.getAnchorU(), iconFactory.getAnchorV());

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

All other answers didn't work for me , got an example from google that solved the issue:
How to replace marker image with textview in google maps api for android?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!