I just started using Google Maps Utils library so that I can have markers with text in them. I understand the library so far and I'm successfully using it. Code snippet:
IconGenerator icnGenerator = new IconGenerator(this);
Bitmap iconBitmap = icnGenerator.makeIcon(item.placeItemName);
myPlaceItemMarkers.add(mMap.addMarker(new MarkerOptions().position(new LatLng(item.latitude, item.longitude))
.icon(BitmapDescriptorFactory.fromBitmap(iconBitmap)).anchor(0.5f, 0.6f)));
Now I started playing around with styling the window a bit and there are two functions that interest me in particular:
icnGenerator.setBackground(Drawable background);
icnGenerator.setTextAppearance(int resid);
I looked up for info on docs and there's only info for BubbleIconFactory which is deprecated. Could someone tell me how to use these 2 functions? I know setTextAppearance is for changing text style but how do I do it? And if I'm not wrong setBackground is for setting custom marker background, but I don't know how to use that either.
I'm still not completely sure how to use setBackground() because I tried using Drawables but it wouldn't work but I figured out how to use setTextAppearance().
I just made a new style:
<style name="iconGenText">
<item name="android:textSize">14sp</item>
<item name="android:textColor">#000000</item>
</style>
And then applied it to IconGenerator:
IconGenerator icnGenerator = new IconGenerator(this);
icnGenerator.setTextAppearance(R.style.iconGenText);
It works as it should.
Set the background like this:
IconGenerator icnGenerator = new IconGenerator(this);
icnGenerator.setBackground(getResources().getDrawable(R.drawable.marker_background));
marker_background has to be a .9.png file. Like the drawables of the library.
It works pretty good for me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With