gpt4 book ai didi

android - 如何在android中的mapview的overlayitem上绘制独特的标签

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:42:38 25 4
gpt4 key购买 nike

这是我想要实现的东西的截图

enter image description here

我想为 map 的每个覆盖项添加唯一标签(如数字)。我已经完成了添加叠加项并在 map 上显示它们的基本部分。但是这个我卡了很久的地方

最佳答案

您可以使用函数在同一 ItemizedOverlay 上添加具有不同标记的 OverlayItem:

overlayItem.setMarker(drawable);

为此,您需要在 Drawable 上设置边界:

Drawable icon1 = getResources().getDrawable(R.drawable.icon1);
Drawable icon2 = getResources().getDrawable(R.drawable.icon2);
icon1.setBounds(0, 0, icon1.getIntrinsicWidth(), icon1.getIntrinsicHeight());
icon2.setBounds(0, 0, icon2.getIntrinsicWidth(), icon2.getIntrinsicHeight());
OverlayItem item1 = new OverlayItem(new Point(48858290, 2294450),
"Tour Eiffel", "La tour Eiffel");
OverlayItem item2 = new OverlayItem(new Point(48873830, 2294800),
"Arc de Triomphe", "L'arc de triomphe");
item1.setMarker(icon1);
item2.setMarker(icon2);

您将需要与最大标记数一样多的位图。但它比在位图上动态绘制文本要快。这是一部手机,处理器速度不快。如果你更喜欢在 Bitmap 上绘制文本,其实很简单,你可以这样做:

//get a reference on the ImageView 
ImageView iv = (ImageView)findViewById(R.id.myImage);

// load the marker image
Bitmap myRefBitmap = BitmapFactory.decodeResource(getResources(),
R.drawable.icon);

// create a mutable bitmap with the same size as the marker image
Bitmap myWrittenBitmap = Bitmap.createBitmap(myRefBitmap.getWidth(),
myRefBitmap.getHeight(), Bitmap.Config.ARGB_4444);

// create a Canvas on which to draw and a Paint to write text.
Canvas canvas = new Canvas(myWrittenBitmap);
Paint txtPaint = new Paint();
txtPaint.setColor(Color.RED);
txtPaint.setTextSize(12);
txtPaint.setFlags(Paint.ANTI_ALIAS_FLAG);
txtPaint.setTypeface(Typeface.DEFAULT_BOLD);

//draw ref bitmap then text on our canvas
canvas.drawBitmap(myRefBitmap, 0, 0, null);
canvas.drawText("Droid", 5, 15, txtPaint);

// set the new written bitmap into the ImageView
iv.setImageBitmap(myWrittenBitmap);

关于android - 如何在android中的mapview的overlayitem上绘制独特的标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5216228/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com