Apq*_*pqu 4 java maps android openstreetmap osmdroid
好吧,这个问题已经困扰我好几个小时了,我有以下相对简单的代码,可以在 osmdroid 地图上放置一个标记
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);
Run Code Online (Sandbox Code Playgroud)
然而,标记始终面向屏幕顶部(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);
Run Code Online (Sandbox Code Playgroud)
其中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);
}
Run Code Online (Sandbox Code Playgroud)
结果是:

这工作正常,但我建议您使用MyLocationOverlay类
| 归档时间: |
|
| 查看次数: |
3371 次 |
| 最近记录: |