谷歌地图API for android(v2) - 如何添加没有背景的文本?

Dei*_*del 2 android google-maps-android-api-2

我需要text annotation为特定位置(lat,lng)创建一个google map(只是文本no background,作为谷歌地图混合卫星视图中的街道名称).当用户旋转/移动地图时,文本应相应移动.这可能吗?

use*_*624 9

您可以动态创建自己的标记图标,并随意绘制它,当然也只是文本.

public BitmapDescriptor createPureTextIcon(String text) {

    Paint textPaint = new Paint(); // Adapt to your needs

    float textWidth = textPaint.measureText(text);
    float textHeight = textPaint.getTextSize();
    int width = (int) (textWidth);
    int height = (int) (textHeight);

    Bitmap image = Bitmap.createBitmap(width, height, Config.ARGB_8888);
    Canvas canvas = new Canvas(image);

    canvas.translate(0, height);

    // For development only:
    // Set a background in order to see the
    // full size and positioning of the bitmap.
    // Remove that for a fully transparent icon.
    canvas.drawColor(Color.LTGRAY);

    canvas.drawText(text, 0, 0, textPaint);
    BitmapDescriptor icon = BitmapDescriptorFactory.fromBitmap(image);
    return icon;
}
Run Code Online (Sandbox Code Playgroud)