android - 如何在 MapView 上创建动态编号的 Pin 指针?

标签 android google-maps android-mapview

我想在我的 MapView 上显示一些位置。这些位置将显示编号为 1、2、3.. 的图钉(类似于 Google map 结果,但它是 A、B、C..)。我认为拥有所有数字的引脚是不可行的。

有什么方法可以让我用 TextView 创建一个带有图钉背景的布局,然后我将动态地将数字放入 TextView 并且该布局将用作可绘制图钉? ?

或任何其他方法来实现这一目标?请提供一些建议。

(我可以在 MapView 上显示不同的可绘制图钉。我只想动态创建可绘制图)

最佳答案

解决了这个问题。

用 pin 背景填充 TextView 并将位置动态设置到 TextView 中。

public Drawable createFromView(int positionNumber)
{
    LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
    View view = inflater.inflate(R.drawable.pin_icon, null, false);
    TextView tv = (TextView) view.findViewById(R.id.pin_background);
    tv.setText("     "+ (positionNumber+1) );   // +1 since position is starting from 0
    tv.setDrawingCacheEnabled(true);
    tv.layout(0, 0, 50, 50);
    tv.buildDrawingCache();
    Bitmap b = Bitmap.createBitmap(tv.getDrawingCache());
    tv.setDrawingCacheEnabled(false);
    Drawable d = new BitmapDrawable(b);
    return d;
}

关于android - 如何在 MapView 上创建动态编号的 Pin 指针?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6501413/

相关文章:

android - MapView 抛出 IllegalArgumentException - 错误的图像大小 : 192 192

android - 在 com.google.android.maps.MapView 中禁用平移/缩放

android - 使用 volley 获取位置数据并在 Google map 中创建多个标记

android - 当通过搜索栏更改大小时,Android v2 版 Google map 上的圆圈会闪烁

javascript - Google map 更改标记数据而不删除/创建 (MarkerWithLabel)

android - 为什么 MapView 显示灰色图 block 而不是 map ?

android - 我无法从 gitlab 存储库中发布包含两个包的包

android - 如何取消onPause或onStop方法?

android - 使用 Android 联系人应用程序编辑由自定义 ContentProvider 添加的原始联系人

android - 如何在 Android 上使用室内信标实时映射