我制作了一款安卓应用程序,我想在标记上方(或下方)添加文本。我找到了这个链接How to add text above a marker on Google Maps?,但它是针对旧版的Google地图API的。所以我想知道我们是否可以使用新版API实现同样的功能?
我曾尝试使用以下代码来实现:
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))
);
但是文本只能以位图形式显示(不能在上方/下方显示)!