我正在尝试使用osmdroid为我的离线地图进行两次手指旋转。我是新手使用map for android。我有一个geoTIFF,我打算使用NDK提取信息,然后将其发送给JAVA。我还需要使用geoPoint与True North Up对齐。我该怎么办,有什么帮助?
我试过这个: Android Two finger rotation 例如,但没有运气,我的应用程序无法检测到任何两个手指事件。
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mResourceProxy = new DefaultResourceProxyImpl(getApplicationContext());
setContentView(R.layout.activity_main);
mapView = (MapView)findViewById(R.id.mapview);
//Mapview touch utilities
mapView.setClickable(true);
mapView.setBuiltInZoomControls(true);
mapView.setMultiTouchControls(true);
//set initial zoom-level, depends on your need
mapView.getController().setZoom(nMyZoom);
//Display Position Overlay
/* Itemized Overlay */
{
/* Create a static ItemizedOverlay showing a some Markers on some cities. */
final ArrayList<OverlayItem> items = new ArrayList<OverlayItem>();
items.add(new OverlayItem("Fruchthalle", "Kaiserslautern", new GeoPoint(nMyLat, nMyLong)));
/* OnTapListener for the Markers, shows a simple Toast. */
this.mMyLocationOverlay = new ItemizedIconOverlay<OverlayItem>(items,
new ItemizedIconOverlay.OnItemGestureListener<OverlayItem>() {
@Override
public boolean onItemSingleTapUp(final int index, final OverlayItem item) {
Toast.makeText(
MainActivity.this,
"Place '" + item.getTitle()+ "' (index=" + index
+ ") got single tapped up", Toast.LENGTH_LONG).show();
return true; // We 'handled' this event.
}
@Override
public boolean onItemLongPress(final int index, final OverlayItem item) {
Toast.makeText(
MainActivity.this,
"Place '" + item.getTitle() + "' (index=" + index
+ ") got long pressed", Toast.LENGTH_LONG).show();
return false;
}
}, mResourceProxy);
this.mapView.getOverlays().add(this.mMyLocationOverlay);
}
答案 0 :(得分:2)
您是否看过OpenStreetMapViewer示例应用?其中有RotationGestureOverlay叠加层,专门展示了如何执行此操作。它并不像我想的那样顺利,但它会完成这项工作。
答案 1 :(得分:2)
为简单起见,请使用以下类:
public class RotationGestureDetector {
public interface RotationListener {
public void onRotate(float deltaAngle);
}
protected float mRotation;
private RotationListener mListener;
public RotationGestureDetector(RotationListener listener) {
mListener = listener;
}
private float rotation(MotionEvent event) {
double delta_x = (event.getX(0) - event.getX(1));
double delta_y = (event.getY(0) - event.getY(1));
double radians = Math.atan2(delta_y, delta_x);
return (float) Math.toDegrees(radians);
}
public void onTouch(MotionEvent e) {
if (e.getPointerCount() != 2)
return;
if (e.getActionMasked() == MotionEvent.ACTION_POINTER_DOWN) {
mRotation = rotation(e);
}
float rotation = rotation(e);
float delta = rotation - mRotation;
mRotation += delta;
mListener.onRotate(delta);
}
}
和
public class RotationGestureOverlay extends Overlay implements RotationGestureDetector.RotationListener
{
private final RotationGestureDetector mRotationDetector;
private RotationGestureDetector.RotationListener rotationListener;
public RotationGestureOverlay(Context context, RotationGestureDetector.RotationListener rotationListener)
{
super(context);
this.rotationListener = rotationListener;
mRotationDetector = new RotationGestureDetector(this);
}
@Override
public boolean onTouchEvent(MotionEvent event, MapView mapView)
{
if (this.isEnabled()) {
mRotationDetector.onTouch(event);
}
return super.onTouchEvent(event, mapView);
}
@Override
public void onRotate(float deltaAngle)
{
rotationListener.onRotate(deltaAngle);
}
@Override
public void draw(Canvas canvas, MapView mapView, boolean b) {
}
}
添加叠加层:
mapView.getOverlays().add(new RotationGestureOverlay(context,this);