围绕任意点旋转osmdroid地图

时间:2016-04-13 11:45:19

标签: android osmdroid

我需要围绕当前位置标记旋转我的地图。当前位置标记将放置在地图的底部。喜欢在图片上。 Map with location marker

1 个答案:

答案 0 :(得分:0)

我用这段代码解决了我的任务:

//rotate map
map.setMapOrientation(angle);

//center to current location
GeoPoint point = mMyLocationNewOverlay.getMyLocation();
if (point == null) return;
mapController.setCenter(point);

//calculate translation
float bottomPadding = map.getHeight() * 0.1f;
float radius = map.getHeight()/2 - bottomPadding;
double deltaW = Math.sin(Math.toRadians(angle));
double deltaH = Math.cos(Math.toRadians(angle));

int width = map.getWidth()/2 - (int)(radius * deltaW);
int height = map.getHeight()/2 - (int)(radius * deltaH);

//Move current location marker to bottom of the map
Projection projection = map.getProjection();
GeoPoint centerPoint = (GeoPoint) projection.fromPixels(width, height);
mapController.setCenter(centerPoint);