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) !
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.
if you just need to add text above a marker, do something like this:
mMap.addMarker(new MarkerOptions().position(point).title(
"fsdfsdf sdfsdf")).showInfoWindow();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With