1

我已经通过这个堆栈溢出和其他具有反向地理编码的相关文章浏览了几篇文章。

我打算从触摸事件中找到具有给定纬度和经度的地方的名称。我从触摸事件中获得了纬度和经度,但我无法从该地理坐标中获得地址,它通过异常而不是在尝试区域中,

这是代码:

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;
     }
}   

请让我找到解决方案。

4

2 回答 2

3

所以模拟器 2.2 有与反向地理编码相关的错误。所以我们需要下载2.1这样的版本并尝试。它将提供所需的结果

于 2012-10-01T15:31:51.643 回答
0

你得到什么例外?你的应用程序有INTERNET 权限吗?我很确定你需要这个才能让 Geocoder 工作(因为它通过 Internet 调用 Google 服务)。

于 2012-09-23T18:40:50.820 回答