Search code examples
androidandroid-ndkandroid-mapviewosmdroid

Two finger rotation for OSMdroid mapview


I'm trying to make two finger rotation for my offline maps using osmdroid. I'm new to using maps for android. I have a geoTIFF, I'm planning to extract info using NDK and later send it to JAVA. I need to use the geoPoint to align with True North Up using compass as well. How can I proceed, any help?

I did try this: Android Two finger rotation example, but no luck, my app was not able to detect any two finger event.

@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);
    }

Solution

  • Have you taken a look at the OpenStreetMapViewer sample app? There is the RotationGestureOverlay overlay in there that specifically shows how to do this. It isn't as smooth as I would like it, but it will do the job.