gpt4 book ai didi

java - 在 OSMDroid for Android 中旋转标记?

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:09:34 24 4
gpt4 key购买 nike

好吧,这个已经困扰我几个小时了,我有以下相对简单的代码,可以在 osmdroid map 上放置一个标记

final ArrayList<OverlayItem> items = new ArrayList<OverlayItem>();
OverlayItem marker = new OverlayItem("markerTitle", "markerDescription", new GeoPoint(52.033954,1.210179));
marker.setMarkerHotspot(OverlayItem.HotspotPlace.TOP_CENTER);
items.add(marker);

Drawable newMarker = this.getResources().getDrawable(R.drawable.maincar);
DefaultResourceProxyImpl resProxyImp = new DefaultResourceProxyImpl(getApplicationContext());
ItemizedIconOverlay markersOverlay = new ItemizedIconOverlay<OverlayItem>(items, newMarker, null, resProxyImp);
mapView.getOverlays().add(markersOverlay);

然而,标记始终面向屏幕顶部(0 度旋转)。我怎样才能轻松地将每个标记旋转到指定的角度(360 度是一个完整的圆圈)?

最佳答案

尝试像这样使用 RotateMyBitmap 方法:

Bitmap source = BitmapFactory.decodeResource(this.getResources(), R.drawable.ic_launcher);

Bitmap target = RotateMyBitmap(source, 120.0f);

final ArrayList<OverlayItem> items = new ArrayList<OverlayItem>();
OverlayItem marker = new OverlayItem("markerTitle", "markerDescription", new GeoPoint(52.033954,1.210179));
marker.setMarkerHotspot(OverlayItem.HotspotPlace.TOP_CENTER);
items.add(marker);

Drawable newMarker = new BitmapDrawable(getResources(), target);

//Drawable newMarker = this.getResources().getDrawable(R.drawable.maincar);
DefaultResourceProxyImpl resProxyImp = new DefaultResourceProxyImpl(getApplicationContext());
ItemizedIconOverlay markersOverlay = new ItemizedIconOverlay<OverlayItem>(items, newMarker, null, resProxyImp);
mapView.getOverlays().add(markersOverlay);

RotateMyBitmap 在哪里:

public static Bitmap RotateMyBitmap(Bitmap source, float angle)
{
Matrix matrix = new Matrix();
matrix.postRotate(angle);
return Bitmap.createBitmap(source, 0, 0, source.getWidth(), source.getHeight(), matrix, true);
}

结果是:

enter image description here

这很好用,但我建议您使用 MyLocationOverlay

关于java - 在 OSMDroid for Android 中旋转标记?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20519695/

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