mrroboaat
mrroboaat

Reputation: 5702

How to add text above a marker on android Google Maps v2?

I made an android application and i want add text above (or below) a marker. I found this link How to add text above a marker on Google Maps? but it's for the old api of google maps. So i wonder if we can do the same thing with the new api ?

I have ever tried to do this with this code :

    Bitmap.Config conf = Bitmap.Config.ARGB_8888;
    Bitmap bm = BitmapFactory.decodeResource(getResources(), R.drawable.pin_favoris).copy(Bitmap.Config.ARGB_8888, true);
Canvas canvas = new Canvas(bm);
Paint paint = new Paint();
paint.setColor(Color.BLUE);
paint.setTextSize(25);
canvas.drawText("Favoris", 0, bm.getHeight(), paint); // paint defines the text color, stroke width, size
BitmapDrawable draw = new BitmapDrawable(getResources(), bm);
Bitmap drawBmp = draw.getBitmap();
// gMap.moveCamera(CameraUpdateFactory.newLatLngZoom(fakeMarker, 15));
gMap.addMarker(new MarkerOptions()
        .position(fakeMarker)
        .icon(BitmapDescriptorFactory.fromBitmap(drawBmp))
        );

but the text can only be displayed in the Bitmap (not above/below) !

Upvotes: 5

Views: 17362

Answers (3)

Lucas
Lucas

Reputation: 949

if you just need to add text above a marker, do something like this:

mMap.addMarker(new MarkerOptions().position(point).title(
           "fsdfsdf sdfsdf")).showInfoWindow();

Upvotes: 13

D-32
D-32

Reputation: 3255

Why not just make your Bitmap / Canvas bigger, then you can draw your text above the marker.

This should help: How to increase Canvas size in Android?

Upvotes: 0

KunalK
KunalK

Reputation: 1904

Have you tried this :

gMap.addMarker(new MarkerOptions()
    .position(fakeMarker)
    .title("Favoris")
    .icon(BitmapDescriptorFactory.fromResource(R.drawable.pin_favoris))
);

Upvotes: 1

Related Questions