2012-05-26 2 views
0

대상 점을 가리키는 소스의 아이콘에서 오버레이로 작은 화살표를 표시하고 싶습니다. 따라서이 화살표는 소스 위치가 변경 될 때 모든 방향을 가리켜 야합니다. 대상을 가리키는 소스 지점에 표시된 나침반과 같습니다.Android MapView - 대상에 대한 화살표 오버레이

제안 사항? 감사.

답변

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; 

    } 
}