English 中文(简体)
Android MapView - 箭头覆盖到目的地
原标题:Android MapView - Arrow overlay to destination

我想显示一支小箭头作为我源代码标记的重叠, 指向目的地。 因此, 此箭头应该指向各个方向, 随着源位置的变化。 它就像指向目的地的源点所显示的指南针 。

有什么建议吗?

问题回答

我为类似问题找到的解决方案是使用代表箭头的标记图像。 然后我计算出源与目的地之间的角, 于是我用这个角度旋转标记 。 (为我的英语道歉 )

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;

    }
}




相关问题
Custom pin with title subtitle iphone

I have a mapview and i put an annotation which shows a custom title and subtitle pin. When the mapview starts the pin is visible but the title and subtitle are not. I have to press on the pin to show ...

Problem setText UITextView

Hi i have a problem. I have 2 viewcontroller, in the first there is a mapView that implements the function "calloutAccessoryControlTapped" to tap a button on an annotation on the mapView; in the ...

How to layout zoom Control with setBuiltInZoomControls(true)?

would like to add a zoom control to the map. I also want to layout the position of the zoom Control instead of the default middle bottom position. I can do this by getZoomControl but it is deprecated. ...

热门标签