简体   繁体   English

如何在我的自定义osmdroid映射上设置“拖动开始和结束”侦听器?

[英]How to set Drag Start and End listener on my custom osmdroid map?

I need to display a toast for Drag Events in my map, the below is my code in which i get only "Drag Started" message when i do a drag end-event. 我需要在地图中显示“拖动事件”的祝酒词,以下是我的代码,其中在执行拖动结束事件时仅收到“拖动开始”消息。 How can i make it? 我该怎么做?

public void onDragListener() {
    osm.setMapListener(new DelayedMapListener(new MapListener() {

        @Override
        public boolean onScroll(ScrollEvent paramScrollEvent) {
            // public boolean onDrag(boolean b) {
            int drag = DragEvent.ACTION_DRAG_STARTED;
            if (drag == 1) {
                Toast.makeText(getBaseContext(), "Drag Started",
                        Toast.LENGTH_LONG).show();

            }
            int drag1 = DragEvent.ACTION_DRAG_ENDED;
            if (drag1 == 1) {
                Toast.makeText(getBaseContext(), "Drag Stopped",
                        Toast.LENGTH_LONG).show();
            }

            return true;
        }

    }));
}

Any help will be appreciated, Thanks 任何帮助将不胜感激,谢谢

Basically the logic is incorrect it will only show Drag Started Toast. 基本上,逻辑是不正确的,它将仅显示“ Drag Started Toast”。 This is how you can fix the toast. 这是解决烤面包的方法。

Define variable at class level. 在类级别定义变量。

    private Context ctx;

then assign the value 然后分配值

  @Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.select_location);


    ctx = getApplicationContext();

then use it in your code 然后在代码中使用它

map.setMapListener(new DelayedMapListener(new MapListener() {

        @Override
        public boolean onScroll(ScrollEvent paramScrollEvent) {
            // public boolean onDrag(boolean b) {
            IGeoPoint ij = map.getMapCenter();
            Double lat = ij.getLatitude();
            Double lon = ij.getLongitude();

           Toast.makeText(ctx, lat+","+lon, Toast.LENGTH_SHORT).show();


            return true;
        }


       @Override
       public boolean onZoom(ZoomEvent event) {
           return false;
       }

   }));

you can't fire scroll start/end or zoom up/down directly... using 'DelayedMapListener' into setMapListener to fire event with delay. 您不能直接触发滚动开始/结束或直接放大/缩小...使用'DelayedMapListener'进入setMapListener来延迟触发事件。 like this: 像这样:

    map.setMapListener(new DelayedMapListener(new MapListener() {
        @Override
        public boolean onScroll(ScrollEvent event) {
            //do something
            return true;
        }
        @Override
        public boolean onZoom(ZoomEvent event) {
            //do something
            return false;
        }
    }, 100));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM