反向地理编码在Android中使用触摸事件

问题描述:

我已经经历了数篇走过这个堆栈溢出和其他有关条款与反向地理编码。

I have gone through several articles through this stack overflow and other related articles with reverse geocoding.

我已打算找到具有给定的纬度和经度从触摸事件的地点的名称。我从触摸事件的纬度和经度,但我不能得到从地理地址坐标,它通过在异常而不是在try面积为,

I have intended to find the name of the place with the given latitude and longitude from touch event. I got the latitude and longitude from the touch event but I couldn't get the address from that geo coordinate, it passes in the exception rather then being in the try area,

这里是code:

public boolean onTouchEvent(MotionEvent event, MapView mapView)
{
     //---when user lifts his finger---
        //---when user lifts his finger---
         if (event.getAction() == 1) {
         GeoPoint p = mapView.getProjection().fromPixels(
         (int) event.getX(),
         (int) event.getY());
                  Toast.makeText(getBaseContext(),
         p.getLatitudeE6() / 1E6 + "," +
         p.getLongitudeE6() /1E6 ,
         Toast.LENGTH_SHORT).show();

         Geocoder geoCoder = new Geocoder(getBaseContext(), Locale.getDefault());
         try {
         List<Address> addresses = geoCoder.getFromLocation(p.getLatitudeE6() / 1E6, p.getLongitudeE6() / 1E6, 1);

         String strCompleteAddress= "";
         if (addresses.size() > 0)
         {
         for (int i=0; i<addresses.get(0).getMaxAddressLineIndex();i++)
        strCompleteAddress+= addresses.get(0).getAddressLine(i) + "\n";
         }
         Log.i("MyLocTAG => ", strCompleteAddress);
         Toast.makeText(getBaseContext(), strCompleteAddress,            Toast.LENGTH_LONG).show();
         }
         catch (IOException e) {

         e.printStackTrace();
         Toast.makeText(getBaseContext(), "exception", Toast.LENGTH_LONG).show();
         }
         return true;
         }
         else
         return false;
     }
}   

请让我来解决吧。

这样模拟器2.2有BUG与反向地理编码相关联。因此,我们需要下载的版本像2.1和尝试。它将提供所需的结果

so The emulator 2.2 has bug associated with Reverse Geocoding. So we need to download version like 2.1 and try. It will provide the desired result