2013-10-19 23 views
1

我正在使用dispatchTouchEvent()方法来点击地图。当我点击布局上的任何地方时,它会显示经纬度,但我希望它只在点击地图区域时显示。我不知道自己做错了什么,此代码:在OpenStreetMap中点按位置地址Android

@Override 
public boolean dispatchTouchEvent(MotionEvent ev) { 
    int actionType = ev.getAction(); 
    switch (actionType) { 
    case MotionEvent.ACTION_UP: 

     proj = mapView.getProjection(); 
     loc = (GeoPoint) proj.fromPixels((int) ev.getX(), (int) ev.getY()); 
     String longitude = Double 
       .toString(((double) loc.getLongitudeE6())/1000000); 
     String latitude = Double 
       .toString(((double) loc.getLatitudeE6())/1000000); 
     Toast toast = Toast.makeText(getApplicationContext(), "Longitude: " 
       + longitude + " Latitude: " + latitude, Toast.LENGTH_SHORT); 
     toast.show(); 

    } 
    return super.dispatchTouchEvent(ev); 
} 

这里是布局的图像:

+1

你能帮我吗? –

回答

1

最后我已经解决了这一点。在这里你可以看到他的解决方案

@Override 
    public boolean onSingleTapConfirmed(MotionEvent e, MapView mapView) { 

     Projection proj = mapView.getProjection(); 
     p = (GeoPoint) proj.fromPixels((int) e.getX(), (int) e.getY()); 
     proj = mapView.getProjection(); 
     loc = (GeoPoint) proj.fromPixels((int) e.getX(), (int) e.getY()); 
     String longitude = Double 
     .toString(((double) loc.getLongitudeE6())/1000000); 
     String latitude = Double 
     .toString(((double) loc.getLatitudeE6())/1000000); 
     Toast toast = Toast.makeText(getApplicationContext(), 
     "Longitude: " 
     + longitude + " Latitude: " + latitude, Toast.LENGTH_SHORT); 
     toast.show(); 
     return true; 
    }