如何在android中的mapview的overlayitem上绘制唯一标签

时间:2011-03-07 05:36:57

标签: android google-maps overlayitem

以下是我正在尝试实现的内容的截图

enter image description here

我想为地图的每个叠加层添加唯一标签(如数字)。我已经完成了添加overlayitems并在地图上显示它们的基本部分。但这就是我被困了很长时间

1 个答案:

答案 0 :(得分:6)

您可以使用以下功能在同一OverlayItem上添加ItemizedOverlay不同标记:

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上绘制文本,Ii非常简单,您可以这样做:

//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);