android - Google map 问题上的自定义标记

标签 android google-maps android-canvas android-bitmap

在 Bitmap 和 canvas 的帮助下,我在我的 Google Map App 中使用了一个自定义标记。当我在 Android 版本 5.1 或除 4.4 以外的任何其他设备上运行它时,标记上的图像变得很好。

我确定这不是版本问题。但我很困惑,无法弄清楚我在哪里做错了。请帮我找到它。

自定义标记(位图)代码:

Bitmap.Config conf = Bitmap.Config.ARGB_8888;
            Bitmap bmp = Bitmap.createBitmap(128, 128, conf);
            Canvas canvas1 = new Canvas(bmp);


    canvas1.drawBitmap(BitmapFactory.decodeResource(getResources(),
                        R.drawable.map_markers_green), 0, 0, color);

                canvas1.drawText(String.valueOf(a).toUpperCase(), 56, 53, color);
                googleMap.addMarker(new MarkerOptions()
                        .icon(BitmapDescriptorFactory.fromBitmap(bmp))
                                // Specifies the anchor to be at a particular point in the marker image.
                        .anchor(0.5f, 1));

在设备上运行良好的标记图像:

enter image description here

即将在不同设备上剪切的相同标记图像:

enter image description here

最佳答案

试试这个代码

Bitmap.Config conf = Bitmap.Config.ARGB_8888;
Bitmap bmp = Bitmap.createBitmap(200, 50, conf); 
 Canvas canvas = new Canvas(bmp);
canvas.drawText("TEXT", 0, 50, paint); // paint defines the textcolor, stroke width, size
 mMap.addMarker(new MarkerOptions()
                            .position(clickedPosition)
                            //.icon(BitmapDescriptorFactory.fromResource(R.drawable.marker2))
                            .icon(BitmapDescriptorFactory.fromBitmap(bmp))
                            .anchor(0.5f, 1)
                                );

关于android - Google map 问题上的自定义标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34743485/

相关文章:

ios UITextView 没有出现在 map 上

Android:使用渐变填充颜色在 canvas api 中绘制圆弧

Java Android Canvas.drawText(...) 在所有屏幕上同样大

java - 处理空 ArrayList 的 Android BaseAdapter

javascript - 强制 Google Maps Javascript API 进入 Lite 模式

java - "Swig to java (Android)": giving No such file or directory Error on generating Swig to Java file

javascript - GmapPanel 在点击时添加标记 - EXTJS

java - 如何使用canvas随机绘制?

android - Xamarin Android Player 显示 0 个可下载设备?

java - Android LocationListener onLocationChanged() 永远不会被调用