我已经创建了返回我当前位置完整地址的代码,但我希望它只返回当前位置的某些方面,例如只是邮政编码,就是县等。

              //Place your latitude and longitude
              List<Address> addresses = geocoder.getFromLocation(lati,longi, 1);

              if(addresses != null) {

                  Address fetchedAddress = addresses.get(0);
                  StringBuilder strAddress = new StringBuilder();

                  for(int i=0; i<fetchedAddress.getMaxAddressLineIndex(); i++) {
                        strAddress.append(fetchedAddress.getAddressLine(i)).append("\n");
                  }

                 String Address= strAddress.toString();

                 Toast.makeText(getApplicationContext(),Address, Toast.LENGTH_LONG).show();


那是我到目前为止的代码,如果有人可以向我指出教程的指导甚至就此问题为我提供帮助,将不胜感激

最佳答案

您已经准备就绪。查询地址对象以获取信息:

fetchedAddress.getPostalCode() //zipcode
fetchedAddress.getLocality() //city


http://developer.android.com/reference/android/location/Address.html

07-27 16:27