用户触摸的Andr​​oid MapView类返回一个GeoPoint对象 [英] Returning a GeoPoint on user touch MapView Android

查看:107
本文介绍了用户触摸的Andr​​oid MapView类返回一个GeoPoint对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在遇到麻烦试图找出一个方法返回一个GeoPoint的与用户只是触及该位置的经度和纬度。我已经看到和阅读通过覆盖 dispatchTouchEvent()显示经度和纬度举杯吨或例子。
我相信这不会对我的情况,原因如下工作。

I'm having trouble trying to figure out a way to return a GeoPoint with the longitude and latitude of the location the user just touched. I have seen and read tons or examples that display the longitude and latitude in a toast by overriding dispatchTouchEvent(). I believe this won't work for my case for the following reason.

我希望用户能够点击一个按钮,然后将调用将返回用户的水龙头旁边一个GeoPoint的另一种方法。因此,简而言之,一个GeoPoint对象只水龙头的用户点击该按钮后返回。

I want the user to be able click a button that will then call another method that will return a geopoint on the user's next tap. So, in short, a geopoint is only returned on the tap after the user clicks the button.

唯一的工作,我周围可以看到使用 dispatchTouchEvent()如下。

The only work around I can see using the dispatchTouchEvent() is the following.

如果该按钮被点击,写入共享preferences。然后在 dispatchTouchEvent()检查按钮是否已经被点击。如果没有被点击,什么也不做。如果已经写点击经度和纬度的共享preferences,然后从共享preferences阅读并以不同的方法创建的GeoPoint了出来。

If the button has been clicked, write to the shared preferences. Then in dispatchTouchEvent() check to see if the button has been clicked. If it has not been clicked,do nothing. If it has been clicked write the longitude and latitude to shared preferences and then read them from shared preferences and create a GeoPoint out of them in a different method.

我不觉得自己是一个非常优雅的想法。我觉得应该是这样做(如以某种方式返回只是一个GeoPoint对象)

I don't feel like that is a very elegant idea. I feel like there should be a much cleaner way of doing this(like somehow returning just a geopoint)

我希望这是感一点点。我会尽力回答任何问题,我可以。

I hope this makes a little bit of sense. I'll try to answer any questions I can.

先谢谢了。

推荐答案

我刚才读的标题您question..so原谅我,如果把错误的答案..:D

I just read the title of your question..so pardon me if put the wrong answer..:D

    mapView.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            // TODO Auto-generated method stub
            GeoPoint p = null;

            if (event.getAction() == MotionEvent.ACTION_UP) {
                p = mapView.getProjection().fromPixels((int) event.getX(),
                        (int) event.getY());
                mapBackButton.setText(p.getLatitudeE6() / 1E6 + ","
                        + p.getLongitudeE6() / 1E6 + "Action is : "
                        + event.getAction());
                return true;
                Toast.makeText(
                        getBaseContext(),
                        p.getLatitudeE6() / 1E6 + "," + p.getLongitudeE6()
                                / 1E6 + "Action is : " + event.getAction(),
                        Toast.LENGTH_SHORT).show();
            }
            return false;
        }
    });

这篇关于用户触摸的Andr​​oid MapView类返回一个GeoPoint对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆