MyLocationOverlay의 "You Are Here"지점에 사용자 정의 비트 맵을 어떻게 사용할 수 있습니까?
-
09-09-2019 - |
문제
나는 문서에 쏟아졌고 이것을 알아낼 수 없었습니다. 가능합니까?
해결책
이를 수행하는 올바른 메커니즘은 MyLocationOverLay를 확장 한 다음 DrawMylocation () 보호 메소드를 무시하는 것 같습니다.
다음은 화살표를 사용하여 "당신"이 어디에 있고 "당신"이 어디에 있는지 보여줍니다.
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;
}
}
다른 팁
화살표가 잘못된 방향을 가리키고 반대 방향으로 회전하기 때문에 Previuos 코드를 제대로 작동시키기 위해 몇 가지 변경을했습니다.
나는 바뀌었다
matrix.postRotate(mOrientation);
~을 위한
matrix.postRotate(this.getRotation());
그리고 끝에 추가 :
mapView.postInvalidate();
화살이 변할 때 화살표를 다시 그리십시오
제휴하지 않습니다 StackOverflow