1

Our designer has provided me with a custom icon to display on maps. Our MapView will display several icons of those at the same time.

The tricky part: every icon should have a text above it displaying what it is - and all icons should show this text always simultaneously.

So I know that there is .showInfoWindow(), but that only shows one window at a time and only onclick.

I found this SO post: Map Markers with text in Google Maps Android API v2

but that's using google's library and it only is able to use a colored rectangle as a text holder, not, as in my case, an icon AND the text above.

Searching, I found several ideas but none seems to work. My last attempt:

 LatLng pos = new LatLng(lat, lng);

                Bitmap bm = BitmapFactory.decodeResource(getResources(), R.drawable.icon).copy(Bitmap.Config.ARGB_8888, true);
                Canvas canvas = new Canvas(bm);
                Paint paint = new Paint();
                paint.setStyle(Paint.Style.FILL);
                paint.setColor(Color.WHITE);
                paint.setTextAlign(Paint.Align.CENTER);
                paint.setTextSize(11));
                canvas.drawText(item.getString("name"), 10, -20, paint);

                Marker marker = mMap.addMarker(new MarkerOptions()
                                .position(pos)
                                .title(item.getString("name"))
                                .icon(
                                    BitmapDescriptorFactory.fromBitmap(bm)
                                        )

                );

But I still can only see the icon and no text.

Community
  • 1
  • 1
transient_loop
  • 5,984
  • 15
  • 58
  • 117
  • what is 10 and -20 in drawText? read drawText() docs in order to know how it works – pskink Apr 29 '15 at 19:58
  • I think your last attempt should work, it has to be padding and the position – kaho Apr 29 '15 at 21:49
  • @pskink right, my thinking was wrong here - changed to 10, 20. kaho indeed it works, but not ok. I get some text above the marker icon, but it is barely readable - it has no background color. I'd need to set a colored background so that the text is readable, but no idea how to do that. Also, the text is currently cut to the width of the icon. It should expand.... – transient_loop Apr 29 '15 at 22:51

1 Answers1

0

MarkerOptions markerOptions = new MarkerOptions(); markerOptions.title(placeName + " : " + vicinity);

Myat Htut
  • 487
  • 2
  • 11
  • 17