【问题标题】:Get latitude and longitude based on city, zip or streetname根据城市、邮编或街道名称获取纬度和经度
【发布时间】:2011-06-12 22:34:35
【问题描述】:

在我当前的 android 应用程序中,我想根据输入的城市名称、街道名称或邮政编码获取地理坐标。我怎样才能做到这一点?

最好的问候, 罗尼

【问题讨论】:

    标签: java android android-emulator android-widget


    【解决方案1】:

    试试这个。

    Geocoder geoCoder = new Geocoder(getBaseContext(), Locale.getDefault());
    try {
        List<Address> addresses = geoCoder.getFromLocation(latitude , longitude, 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) {
        Log.i("MyLocTAG => ", "this is the exception part");
        e.printStackTrace();
    }
    

    【讨论】:

      【解决方案2】:

      查看方法Geocoder.getFromLocationName(cityName, maxResults)

      像这样使用它:

      List<Address> addressList = geoCoder.getFromLocationName(cityName, 1);
      Address address = addressList.get(0);
      if(address.hasLatitude() && address.hasLongitude()){
          double selectedLat = address.getLatitude();
          double selectedLng = address.getLongitude();
      }
      

      【讨论】:

        【解决方案3】:

        嗨,

        有一个很好的网站叫做 拥有您所需数据的世界地名词典 需要,在一个整洁的、可下载的文件中(通过 城市名称)

        http://www.world-gazetteer.com/home.htm

        从主页,点击链接 上面写着:

        其他统计......各种 统计数据:表格、地图和 可下载数据

        然后从出现的页面中,单击 在链接上写着:

        popdata (1.4 MB)

        解压文件,搞定!

        数据库是免费主数据库 世界城市,其中包括 纬度、经度和人口 数据...等

        从:http://answers.google.com/answers/threadview?id=432778得到这个

        【讨论】:

        • 从其他答案来看,我认为Geocoder 可能是更好的解决方案,而不是下载地点和坐标数据库。
        【解决方案4】:

        您好,请尝试以下代码从给定地址获取地理编码点。

        List<Address> foundGeocode = null;
        /* find the addresses  by using getFromLocationName() method with the given address*/
        foundGeocode = new Geocoder(this).getFromLocationName("address here", 1);
         foundGeocode.get(0).getLatitude(); //getting latitude
         foundGeocode.get(0).getLongitude();//getting longitude
        

        【讨论】:

          猜你喜欢
          • 2013-10-10
          • 1970-01-01
          • 2013-12-09
          • 1970-01-01
          • 2013-03-03
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多