【问题标题】:Simple example reverse geocoding osmdroid简单示例反向地理编码 osmdroid
【发布时间】:2014-04-07 23:59:18
【问题描述】:

我正在寻找一个使用 osmdroid 进行反向地理编码的简单示例。 我必须将 nominatimAPI 与 JSON 等一起使用吗? 我听说使用 Geocoder 类做同样的事情,但它似乎太容易了...... 当我尝试执行请求时,类 RequestBuilder 无法识别是否正常 提名?

谢谢

【问题讨论】:

    标签: map osmdroid nominatim


    【解决方案1】:

    您可以使用OSMBonusPack GeocoderNominatim 类。

    【讨论】:

      【解决方案2】:

      这是一个使用 OSMBonusPack 的示例:

              // declare your map somewhere in the Activity
              map = (MapView) findViewById(R.id.map);
              map.setTileSource(TileSourceFactory.MAPNIK);
              map.setMultiTouchControls(true);
      
              // create a GeoPoint
              final GeoPoint startPoint = new GeoPoint(36.716999, 3.042076);
      
              // Retreive Geocoding data (add this code to an event click listener on a button)
              new AsyncTask<Void, Void, Void>(){
                  @Override
                  protected Void doInBackground(Void... voids) {
                      // Reverse Geocoding
                      GeocoderNominatim geocoder = new GeocoderNominatim(userAgent);
                      String theAddress;
                      try {
                          List<Address> addresses = geocoder.getFromLocation(startPoint.getLatitude(), startPoint.getLongitude(), 1);
                          StringBuilder sb = new StringBuilder();
                          if (addresses.size() > 0) {
                              Address address = addresses.get(0);
                              int n = address.getMaxAddressLineIndex();
                              Log.d("Test", "CountryName: " + address.getCountryName());
                              Log.d("Test", "CountryCode: " + address.getCountryCode());
                              Log.d("Test", "PostalCode " + address.getPostalCode());
      //                        Log.d("Test", "FeatureName " + address.getFeatureName()); //null
                              Log.d("Test", "City: " + address.getAdminArea());
                              Log.d("Test", "Locality: " + address.getLocality());
                              Log.d("Test", "Premises: " + address.getPremises()); //null
                              Log.d("Test", "SubAdminArea: " + address.getSubAdminArea());
                              Log.d("Test", "SubLocality: " + address.getSubLocality());
      //                        Log.d("Test", "SubThoroughfare: " + address.getSubThoroughfare()); //null
      //                        Log.d("Test", "getThoroughfare: " + address.getThoroughfare()); //null
                              Log.d("Test", "Locale: " + address.getLocale());
                              for (int i=0; i<=n; i++) {
                                  if (i!=0)
                                      sb.append(", ");
                                  sb.append(address.getAddressLine(i));
                              }
                              theAddress = sb.toString();
                          } else {
                              theAddress = null;
                          }
                      } catch (IOException e) {
                          theAddress = null;
                      }
                      if (theAddress != null) {
                          Log.d("Test", "Address: " + theAddress);
                      }
      
                      return null;
                  }
              }.execute();
      

      更多教程可以在 wiki 页面中找到: https://github.com/MKergall/osmbonuspack/wiki 希望这会有所帮助。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-10-31
        相关资源
        最近更新 更多