Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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) !

like image 708
mrroboaat Avatar asked Mar 25 '13 09:03

mrroboaat


People also ask

Which of the following is the correct method to add a marker to a Google map object?

To add a marker to a map, it is necessary create a new MarkerOptions object and then call the AddMarker method on a GoogleMap instance. This method will return a Marker object.


1 Answers

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

mMap.addMarker(new MarkerOptions().position(point).title(
           "fsdfsdf sdfsdf")).showInfoWindow();
like image 66
Lucas Avatar answered Oct 01 '22 09:10

Lucas