How do I add text above a marker on a Google v2 Android map?

I made an Android app and want to add text above (or below) the marker. I found this link. How do I add text above the marker on Google Maps? but this is for the old google maps api. So I wonder if we can do the same 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 text can only be displayed in a bitmap (no higher / lower)!

+4
source share
3 answers

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

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

Have you tried this:

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

Why not just increase the size of the bitmap / canvas, then you can draw text above the marker.

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

0
source

All Articles