相关疑难解决方法(0)

获取osmdroid中地图上单击位置的纬度和经度

我已经设法用它来编写一个Android应用程序来跟踪用户位置并使用标记在地图上显示它.这是相关代码:

public class MainActivity extends Activity implements LocationListener {

public MapView mapView;
private LocationManager locationManager;
MyItemizedOverlay myItemizedOverlay = null;
Drawable marker;

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    mapView = (MapView) this.findViewById(R.id.mapview);
    mapView.setUseDataConnection(false);
    mapView.setClickable(true);
    mapView.setBuiltInZoomControls(true);
    mapView.setMultiTouchControls(true);
    mapView.setUseDataConnection(false);
    mapView.setFocusable(true);
    mapView.setFocusableInTouchMode(true);

    mapView.getController().setZoom(16); // set initial zoom-level, depends
                                            // on your need
    marker = getResources().getDrawable(android.R.drawable.star_on);
    int markerWidth = 1;
    int markerHeight = 1;
    marker.setBounds(0, markerHeight, markerWidth, 0);

    locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0,
            0, this); // You can also use LocationManager.GPS_PROVIDER and
                        // …
Run Code Online (Sandbox Code Playgroud)

android dictionary onclick osmdroid

6
推荐指数
1
解决办法
6136
查看次数

单击MapView上的任何位置时获取坐标

我不能让这个工作.我尝试使用下面的代码与onTouchEventand,它不起作用.如果我在方法结束时返回true,我会得到带坐标的toast但不能移动地图,如果我返回false,我可以移动地图但是在用户点击地图后无法显示吐司.如果我做对了,另一个onTap方法仅用于单击叠加层.有没有人想到这个问题?

        public boolean onTouchEvent(MotionEvent arg0, MapView arg1) {

       //super.onTouchEvent(arg0);


       int akcija = arg0.getAction(); 

        if(akcija == MotionEvent.ACTION_UP){
            if(!premik) {
                Projection proj = mapView.getProjection();
                GeoPoint loc = proj.fromPixels((int)arg0.getX(), (int)arg0.getY()); 
                String sirina=Double.toString(loc.getLongitudeE6()/1000000);
                String dolzina=Double.toString(loc.getLatitudeE6()/1000000);

                 Toast toast = Toast.makeText(getApplicationContext(), "Širina: "+sirina+" Dolzina: "+dolzina, Toast.LENGTH_LONG);
                toast.show();
            }
        }     

        else if (akcija == MotionEvent.ACTION_DOWN){

            premik= false;

        }
        else if (akcija== MotionEvent.ACTION_MOVE){             
            premik = true;
        }


        return false;
        //return super.onTouchEvent(arg0);
      }
Run Code Online (Sandbox Code Playgroud)

android android-mapview

3
推荐指数
1
解决办法
6182
查看次数

标签 统计

android ×2

android-mapview ×1

dictionary ×1

onclick ×1

osmdroid ×1