捏放大与OsmdroidOsmdroid

2023-09-05 10:36:50 作者:海风温柔吹

我写了一个映射应用程序,它有两个活动,一个活动显示一个谷歌地图查看时,其他显示使用osmdroid 3.0.5等效视图罐子。

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.

到现在为止我一直在测试上的模拟器只能和功能在面积方面显示和叠加的数据完全一致。现在,我已经运行一个真正的姜饼设备上的应用程序,我注意到了谷歌地图的活动似乎支持捏放大,而Osmdroid一个没有。

Until now I've been testing on emulators only and the functionality is completely identical in terms of area shown and overlay data. Now I have run the app on a real Gingerbread device, I notice that the Google Maps activity seems to support pinch to zoom, whilst the Osmdroid one doesn't.

我没有写具体的捏缩放为谷歌方面或Osmdroid任何code。这两项活动实施OnTouchListener。这两项活动只是一个存根像OnTouch:

I haven't written any code specific to pinch to zoom for the Google side or for Osmdroid. Both activities implement OnTouchListener. Both activities just have a stub for OnTouch like:

@Override
public boolean onTouch(View v, MotionEvent e) {
    // chain it for now
    return false;
}

我在Osmdroid活动的MapView是类: org.osmdroid.views.MapView

有谁知道如何使捏放大工作,osmdroid或知道一个示例应用程序的使用osmdroid,我可以学习和适应到我的应用程序?

Does anybody know how to make pinch to zoom work with osmdroid or know of a sample application using osmdroid that I could study and adapt into my app?

推荐答案

Osmdroid有放大的功能。您将需要设置一个gesturelistener检查捏的动作,此时你应该调用在osmdroid变焦功能。我相信,在osmdroid 3.0.5它是类似于

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.getController.setZoomLevel(someNumber) (mOsm is an instance of the map view).

我有变焦功能工作对面捏(你的手指开始并拢,然后展开)。我建议使用MotionEvent(像你正在做),做这样的事情:

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) { 

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

在code我加的捏交易 - 成品布尔是我在我的计划实施弄清楚何时刷新地图。这应该帮助你了。

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.

如果你正在寻找不同的东西,然后尝试读取的这里。 Android已经支持了捏动作自2010年6月明显。

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