如何在谷歌地图V2默认标记绘制文本 [英] how to draw text in default marker of google map v2

查看:188
本文介绍了如何在谷歌地图V2默认标记绘制文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想提请在谷歌地图V2默认的标记文本。我已经站在我自己的形象,从绘制,但我怎么能在默认的标志更改做到了这一点。

I want to draw text in default marker of Google map v2. I have done this by taking my own image from drawable but how can i change it in default marker.

我的code是

 marker.icon(BitmapDescriptorFactory
          .fromBitmap(drawTextToBitmap(getApplicationContext(), R.drawable.images,"5")));

drawTextToBitmap 方法的。

public static Bitmap drawTextToBitmap(Context gContext,int gResId,String gText) {
    Resources resources = gContext.getResources();
    float scale = resources.getDisplayMetrics().density;
    Bitmap bitmap =
            BitmapFactory.decodeResource(resources, gResId);

    android.graphics.Bitmap.Config bitmapConfig =
            bitmap.getConfig();
    if(bitmapConfig == null) {
        bitmapConfig = android.graphics.Bitmap.Config.ARGB_8888;
    }
    bitmap = bitmap.copy(bitmapConfig, true);

    Canvas canvas = new Canvas(bitmap);
    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setColor(Color.BLACK);
    paint.setTextSize((int) (15 * scale));
    paint.setShadowLayer(1f, 0f, 1f, Color.WHITE);

    Rect bounds = new Rect();
    paint.getTextBounds(gText, 0, gText.length(), bounds);
    int x = (bitmap.getWidth() - bounds.width())/2;
    int y = (bitmap.getHeight() + bounds.height())/2;

    canvas.drawText(gText, x * scale, y * scale, paint);

    return bitmap;
}

我要画这样的文字

i want to draw text like that

推荐答案

1.Downlaod库从

1.Downlaod the library from

github.com/googlemaps/android-maps-utils

github.com/googlemaps/android-maps-utils

2.To使用检查此链接

2.To use check this link

<一个href="http://stackoverflow.com/questions/17796464/using-android-maps-utils-with-adt/17796692#17796692">Using Android的地图-utils的与ADT

  TextIconGenerator tc = new TextIconGenerator(this);
  Bitmap bmp = tc.makeIcon("hello");

然后该位图设置为所述地图对象

Then set the bitmap to the map object

  .icon(BitmapDescriptorFactory.fromBitmap(bmp))); 

快照

这篇关于如何在谷歌地图V2默认标记绘制文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆