Pinch to zoom with Osmdroid

后端 未结 3 1267
感情败类
感情败类 2020-12-31 11:50

I\'ve written a mapping application which has two activities, one activity displays a Google Maps view, the other displays the equivalent view using osmdroid 3.0.5 jar.

相关标签:
3条回答
  • 2020-12-31 12:10

    Osmdroid has the functionality to zoom. You will need to setup a gesturelistener to check for the pinch action, at which point you should call the zoom function in osmdroid. I believe in osmdroid 3.0.5 it is something like

    mOsm.getController.setZoomLevel(someNumber) (mOsm is an instance of the map view).

    I have the zoom function working for the opposite pinch (you fingers start close together and then expand). I suggest using a MotionEvent (like you are currently doing) and doing something like this:

    boolean finished = false;
    
    @Override
    public boolean onTouch(View v, MotionEvent e) {
    
        switch (e.getAction()) {
    
            case MotionEvent.ACTION_DOWN:
                finished = false;
                break;
    
            case MotionEvent.ACTION_MOVE:
                finished = false;
                break;
    
            case MotionEvent.ACTION_UP:
                //action is finishing at this point, so now I can do my refreshActionOnMap();
                if (!finished) 
                    refreshActionOnMap();
                break;
        }
        return true;
    }
    

    The code I have added deals with the pinch - the finished boolean is something I implemented in my program to figure out when to refresh the map. That should help you out more.

    Here is a further explanation of this.

    If you are looking for something different, then try reading here. Android has been supporting the pinch action since June 2010 apparently.

    0 讨论(0)
  • 2020-12-31 12:11
    MapView.setBuiltInZoomControls(true);
    MapView.setMultiTouchControls(true);
    
    0 讨论(0)
  • 2020-12-31 12:21

    Is it possible not to zoom to the map center but to the middle of users two finger.

    0 讨论(0)
提交回复
热议问题