1

我有两个图像一个圆圈和一个箭头。我计算我当前的 GPS 坐标和地图上选择的坐标之间的距离。现在我需要将箭头放在圆形图像上并放在箭头计算距离上。我该如何实施?就像是

在此处输入图像描述

编辑:如何将箭头图像放在中心并在箭头上放置文字?

 public class CompassOverlay extends Overlay
{  
private float angle;

public CompassOverlay(float angle)
{
    this.angle=angle;

}

  @Override
  public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when) {
    super.draw(canvas, mapView, shadow);           

   Bitmap back =BitmapFactory.decodeResource(mapView.getResources(),R.drawable.tfm_compass_back);
   Bitmap arrowBitmap = BitmapFactory.decodeResource(mapView.getResources(),R.drawable.tfm_compass_arrow);

// Create blank bitmap of equal size for back
   Bitmap canvasBitmap = back.copy(Bitmap.Config.ARGB_8888, true);
   canvasBitmap.eraseColor(0x00000000);

   // Create canvas
    Canvas canvasBack = new Canvas(canvasBitmap);

    // Create rotation matrix
    Matrix rotateMatrix = new Matrix();
    rotateMatrix.setRotate(angle, canvasBack.getWidth()/2, canvasBack.getHeight()/2);

    canvas.drawBitmap(back, 0.0f, 0.0f, null);

   // Draw bitmap onto canvas using matrix
    canvasBack.drawBitmap(arrowBitmap, rotateMatrix, null);

    BitmapDrawable bitmapDrawable= new BitmapDrawable(canvasBitmap);
    canvas.drawBitmap(bitmapDrawable.getBitmap(), 0.0f, 0.0f, null);
    return true;
  }


} 

在此处输入图像描述

4

2 回答 2

0

你有一个示例应用程序。转到新建-> 项目-> Android -> Android 示例项目。那里选择 ApiDemoes。那里有一个包含完整代码的 Compass 应用程序

于 2012-09-09T09:23:56.207 回答
0

这看起来很有希望:

  // Create rotation matrix
  Matrix rotateMatrix = new Matrix();
  rotateMatrix.setRotate(angle, canvas.getWidth()/2, canvas.getHeight()/2);

  // Draw bitmap onto canvas using matrix
  canvas.drawBitmap(arrowBitmap, rotateMatrix, null);

在这里找到:如何在 MapView 中绘制显示行车方向的箭头?

于 2012-09-09T09:58:26.320 回答