구글 지도의 원점을 화살표가 있는 아이콘으로 바꾸고 방향을 따라 돌리는 방법
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; } }
made a few changes to the previuos code in order to get it to work properly because the arrow was pointing to the wrong direction and rotating in the opposite direction.
I changed matrix.postRotate(mOrientation);
for matrix.postRotate(this.getRotation());
and added to the end: mapView.postInvalidate();
to redraw the arrow when it changes :
http://developer.android.com/reference/com/google/android/maps/MyLocationOverlay.html
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
그림 미리보기 호환 i 구글 Firefox<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 TRANSITIONAL//EN" "HTTP://WWW.W3.ORG/TR/XHTML1/DTD/XHTML1-TRANSITIONAL.DTD"...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.