gpt4 book ai didi

java - 如何为 MyLocationOverlay 中的 "you are here"点使用自定义位图?

转载 作者:太空狗 更新时间:2023-10-29 15:31:31 26 4
gpt4 key购买 nike

我翻遍了文档,还是没能弄明白。有可能吗?

Please see this

最佳答案

看起来正确的机制是扩展 MyLocationOverlay,然后覆盖 drawMyLocation() protected 方法。

下面用箭头表示“你”在哪里以及“你”指向的方向:



包 com.example;

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

公共(public)类 MyCustomLocationOverlay 扩展 MyLocationOverlay {
私有(private)上下文 mContext;
私有(private) float 方向;

public MyCustomLocationOverlay(上下文上下文,MapView mapView){
super (上下文, map View );
mContext = 上下文;
}

@覆盖
protected void drawMyLocation(Canvas canvas, MapView mapView, Location lastFix, GeoPoint myLocation, long when) {
//将 GeoPoint 转换为屏幕像素
点screenPts = mapView.getProjection().toPixels(myLocation, null);

//创建标记的旋转副本
位图 arrowBitmap = BitmapFactory.decodeResource( mContext.getResources(), R.drawable.arrow_green);
矩阵matrix = new Matrix();
matrix.postRotate(mOrientation);
位图 rotatedBmp = Bitmap.createBitmap(
箭头位图,
0, 0,
arrowBitmap.getWidth(),
arrowBitmap.getHeight(),
矩阵,
真的
);
//将旋转标记添加到 Canvas
canvas.drawBitmap(
旋转Bmp,
screenPts.x - (rotaatedBmp.getWidth()/2),
screenPts.y - (rotaatedBmp.getHeight()/2),
无效的
);
}

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

关于java - 如何为 MyLocationOverlay 中的 "you are here"点使用自定义位图?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/753793/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com