3

I need to make a text annotation for a specific location (lat,lng) on google map (just text with no background, as street names in google map hybrid satellite view). The text should move accordingly when user rotates/moves the map. Is this possible?

Deinlandel
  • 1,023
  • 8
  • 25
  • 1
    have u tried [is possible to create a transparent info window with map v2?](http://stackoverflow.com/questions/19045793/is-possible-to-create-a-transparent-info-window-with-map-v2) – Kaushik Aug 28 '14 at 08:59
  • kaushik, I will see if that's what I need. – Deinlandel Aug 28 '14 at 09:00

2 Answers2

12

You can create you own Marker-Icon dynamically and draw into it whatever you want, of course also text only.

public BitmapDescriptor createPureTextIcon(String text) {

    Paint textPaint = new Paint(); // Adapt to your needs

    float textWidth = textPaint.measureText(text);
    float textHeight = textPaint.getTextSize();
    int width = (int) (textWidth);
    int height = (int) (textHeight);

    Bitmap image = Bitmap.createBitmap(width, height, Config.ARGB_8888);
    Canvas canvas = new Canvas(image);

    canvas.translate(0, height);

    // For development only:
    // Set a background in order to see the
    // full size and positioning of the bitmap.
    // Remove that for a fully transparent icon.
    canvas.drawColor(Color.LTGRAY);

    canvas.drawText(text, 0, 0, textPaint);
    BitmapDescriptor icon = BitmapDescriptorFactory.fromBitmap(image);
    return icon;
}
user2808624
  • 2,502
  • 14
  • 28
  • Thank you for the example. I proposed an edit to fix minor issues width text height calculation and positioning. – Deinlandel Aug 29 '14 at 07:50
0

Yes it is possible, but you can't add directly to the map. You have to add a textview to a relative layout above your map view.

The tricky part, will be the position into the map you will put the textview. You have to convert your coordinates latitude and longitude into x, y position and then adjust the textview in the relativelayout.

This link can help you to convert your coordenates. Converting Longitude & Latitude to X Y on a map with Calibration points

Community
  • 1
  • 1
jobernas
  • 686
  • 1
  • 12
  • 24
  • This solution can be used only if map is not moving, right? Not my case, unfortunately. Edited the question to be more clear. – Deinlandel Aug 28 '14 at 09:22
  • Yes the map must be fixed or else it will be very hard to update the textview while you are dragging the mapview. What you can do is to show the textview when the user stop touching the mapview. I don't see other option. – jobernas Aug 28 '14 at 09:42