0

ソースのマーカーから目的地を指すオーバーレイとして小さな矢印を表示したいと思います。したがって、ソースの場所が変わると、この矢印はすべての方向を指しているはずです。出発点に表示された羅針盤が目的地を指しているようなものです。

助言がありますか?ありがとう。

4

1 に答える 1

2

同様の問題に対して私が見つけた解決策は、矢印を表すマーカーに画像を使用することです。次に、ソースと宛先の間の角度を計算し、この角度でマーカーを回転させます。(私の英語でごめんなさい)。

protected class yourOverlay extends Overlay{
   public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when){
      super.draw(canvas, mapView, shadow);
      Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.arrow);
      Point sourceCoords = new Point();
      mapView.getProjection().toPixels(sourcePosition, sourceCoords);
      int x = sourceCoords.x - bmp.getWidth()/2;
      int y = sourceCoords.y - bmp.getHeight();
      Point destinationCoords = new Point();
      mapView.getProjection().toPixels(destinationPosition, destinationCoords);
      double angle = Math.toDegrees(Math.atan2(sourceCoords.x - destinationCoords.x, sourceCoords.y - destinationCoords.y));
      Matrix matrix = new Matrix();         
      matrix.postRotate(-(float)angle, bmp.getWidth()/2,bmp.getHeight());
      matrix.postTranslate(x,y);
      canvas.drawBitmap(bmp, matrix, new Paint());
      return true;

    }
}
于 2012-11-20T15:23:12.740 に答える