2009-04-15 5 views

답변

14

그것은이 작업을 수행하는 정확한 메커니즘처럼 보인다는 MyLocationOverlay은 다음 drawMyLocation() 보호 메소드를 오버라이드 (override) 확장하는 것이다.

package com.example; 

import android.content.Context; 
import android.graphics.Bitmap; 
import android.graphics.BitmapFactory; 
import android.graphics.Canvas; 
import android.graphics.Matrix; 
import android.graphics.Point; 
import android.location.Location; 
import com.google.android.maps.GeoPoint; 
import com.google.android.maps.MapView; 
import com.google.android.maps.MyLocationOverlay; 

public class MyCustomLocationOverlay extends MyLocationOverlay { 
    private Context mContext; 
    private float mOrientation; 

    public MyCustomLocationOverlay(Context context, MapView mapView) { 
     super(context, mapView); 
     mContext = context; 
    } 

    @Override 
    protected void drawMyLocation(Canvas canvas, MapView mapView, Location lastFix, GeoPoint myLocation, long when) { 
     // translate the GeoPoint to screen pixels 
     Point screenPts = mapView.getProjection().toPixels(myLocation, null); 

     // create a rotated copy of the marker 
     Bitmap arrowBitmap = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.arrow_green); 
     Matrix matrix = new Matrix(); 
     matrix.postRotate(mOrientation); 
     Bitmap rotatedBmp = Bitmap.createBitmap(
      arrowBitmap, 
      0, 0, 
      arrowBitmap.getWidth(), 
      arrowBitmap.getHeight(), 
      matrix, 
      true 
     ); 
     // add the rotated marker to the canvas 
     canvas.drawBitmap(
      rotatedBmp, 
      screenPts.x - (rotatedBmp.getWidth()/2), 
      screenPts.y - (rotatedBmp.getHeight()/2), 
      null 
     ); 
    } 

    public void setOrientation(float newOrientation) { 
     mOrientation = newOrientation; 
    } 
} 

+0

변경 될 때 화살표를 묘화하는

mapView.postInvalidate(); 

비트 맵,하지만 회전되지 않습니다 – marimaf

2

내가 그것을 작동하도록하기 위해 previuos 코드에 몇 가지 변경을했다 :

다음은 "당신이"하고 어떤 방법으로 "당신이"가리키는 곳에 표시하는 화살표를 사용하여 왜냐하면 화살표가 잘못된 방향을 가리키고 반대 방향으로 회전했기 때문입니다.

제가

matrix.postRotate(this.getRotation()); 

위한

matrix.postRotate(mOrientation); 

변경하고 마지막에 추가 : 그것은 I가 변화 할 수 있었다

+0

어떻게 getRotation()을 구현 했습니까? 덕분에 – marimaf

+0

'getRotation()'이 이미'MyLocationOverlay'에 구현되었습니다. –

+0

getOrientation()으로 변경된 것 같습니다. –