标记图标内的 Android Google Maps API 字符串

标签 android string google-maps icons google-maps-markers

有没有一种方法可以将字符串值放入 Google Maps API 2.0 上的 Marker 图标中? 喜欢这张图片

this img

简单来说。有点像这样:

   map.addMarker(new MarkerOptions()
                    .position(POSITION)
                    .title("Your title")
                    .icon(HERE PUT MY VAR STRING)
            );

最佳答案

您可以使用您的文字自定义图标:

Bitmap.Config conf = Bitmap.Config.ARGB_8888;
Bitmap bmp = Bitmap.createBitmap(80, 80, conf);
Canvas canvas = new Canvas(bmp);

// paint defines the text color, stroke width and size
Paint color = new Paint();
color.setTextSize(35);
color.setColor(Color.BLACK);

// modify canvas
canvas.drawText(YOUR_STRING, 30, 40, color);

// add marker to Map
mMap.addMarker(new MarkerOptions().position(USER_POSITION)
    .icon(BitmapDescriptorFactory.fromBitmap(bmp)));

关于标记图标内的 Android Google Maps API 字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37626354/

相关文章:

android - 谷歌云消息 : How to use SHA1 certificate?

javascript - 在网页上包含不引人注目的信息的最佳方式

android - import com.google.android.gms.location.LocationClient格式化电脑后无法解决

android - 空间不足时使用替代布局

python - 'str' 不支持来自 Python2 的缓冲区接口(interface) Python3

python - 重新排列字符,使所有辅音出现在元音之前

javascript - 在一个循环中生成一组标记,并为所有标记分配不同的弹出窗口

javascript - 放大时谷歌地图和标记聚类器出现奇怪的问题

android - RecyclerView Adapter 和 RecyclerView LayoutManager 的职责和区别是什么?

android - 如何将微调器中的文本放入文件?