Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Maps Utils IconGenerator text styles and background

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.

like image 205
Guy Avatar asked Dec 26 '13 21:12

Guy


2 Answers

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.

like image 113
Guy Avatar answered Nov 20 '22 10:11

Guy


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.

like image 24
MEX Avatar answered Nov 20 '22 11:11

MEX