customize the pin of map Android

2019-04-02 02:57发布

问题:

Hello I would like to add a dynamic display with a number in my point.

As in the picture, I already have the icons on the map.

Adding the numbers in point?

回答1:

You may use android-maps-utils to achieve such effect.

Simply create 9-patch out of your pin with empty rectangle above and make rectangle be the content.

Then use IconGenerator to create a Bitmap with your text and 9-patch like here:

IconGenerator factory = new IconGenerator(context);
factory.setBackground(your9PatchDrawable);
factory.setContentView(textViewWithWith3Point600String);
Bitmap icon = factory.makeIcon();

Then use this Bitmap to set Markers icon:

map.addMarker(new MarkerOptions().icon(BitmapDescriptorFactory.fromBitmap(icon)...);