Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/215.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 我如何使用自定义位图来;“你在这里”;我的位置中的一点溢出?_Java_Android_Bitmap_Android Mapview_Mylocationoverlay - Fatal编程技术网

Java 我如何使用自定义位图来;“你在这里”;我的位置中的一点溢出?

Java 我如何使用自定义位图来;“你在这里”;我的位置中的一点溢出?,java,android,bitmap,android-mapview,mylocationoverlay,Java,Android,Bitmap,Android Mapview,Mylocationoverlay,我把文件都翻了一遍还没弄明白。有可能吗 这样做的正确机制似乎是扩展MyLocationOverlay,然后重写drawMyLocation()受保护的方法 下面使用箭头显示“您”所在的位置以及“您”指向的方向: package com.example; import android.content.Context; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.gra

我把文件都翻了一遍还没弄明白。有可能吗


这样做的正确机制似乎是扩展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);
为了

并在最后加上:

mapView.postInvalidate();

要在箭头更改时重新绘制

我可以更改位图,但旋转不起作用
getRotation()
已在
MyLocationOverlay
中实现,它似乎已更改为getOrientation()
mapView.postInvalidate();