android.location.Address.getSubAdminArea()方法的使用及代码示例

x33g5p2x  于2022-01-15 转载在 其他  
字(8.9k)|赞(0)|评价(0)|浏览(196)

本文整理了Java中android.location.Address.getSubAdminArea()方法的一些代码示例,展示了Address.getSubAdminArea()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Address.getSubAdminArea()方法的具体详情如下:
包路径:android.location.Address
类名称:Address
方法名:getSubAdminArea

Address.getSubAdminArea介绍

暂无

代码示例

代码示例来源:origin: square/assertj-android

  1. public AddressAssert hasSubAdminArea(String area) {
  2. isNotNull();
  3. String actualArea = actual.getSubAdminArea();
  4. assertThat(actualArea) //
  5. .overridingErrorMessage("Expected sub-admin area <%s> but was <%s>.", area, actualArea) //
  6. .isEqualTo(area);
  7. return this;
  8. }

代码示例来源:origin: com.squareup.assertj/assertj-android

  1. public AddressAssert hasSubAdminArea(String area) {
  2. isNotNull();
  3. String actualArea = actual.getSubAdminArea();
  4. assertThat(actualArea) //
  5. .overridingErrorMessage("Expected sub-admin area <%s> but was <%s>.", area, actualArea) //
  6. .isEqualTo(area);
  7. return this;
  8. }

代码示例来源:origin: stackoverflow.com

  1. List<Address> addresses = new Geocoder(<CurrentActivityName>.this,Locale.getDefault()).getFromLocation(cur_lat, cur_lon, 1);
  2. Address addr= addresses.get(0);
  3. String Country=addr.getCountryName();
  4. String State=addr.getSubAdminArea();
  5. String City=addr.getLocality();

代码示例来源:origin: stackoverflow.com

  1. Geocoder gc = new Geocoder(context);
  2. if(gc.isPresent()){
  3. List<Address> list = gc.getFromLocation(37.42279, -122.08506,1);
  4. Address address = list.get(0);
  5. StringBuffer str = new StringBuffer();
  6. str.append("Name: " + address.getLocality() + "\n");
  7. str.append("Sub-Admin Ares: " + address.getSubAdminArea() + "\n");
  8. str.append("Admin Area: " + address.getAdminArea() + "\n");
  9. str.append("Country: " + address.getCountryName() + "\n");
  10. str.append("Country Code: " + address.getCountryCode() + "\n");
  11. String strAddress = str.toString();
  12. }

代码示例来源:origin: stackoverflow.com

  1. StringBuilder _homeAddress = null;
  2. try{
  3. _homeAddress = new StringBuilder();
  4. Address address = null;
  5. List<Address> addresses = _coder.getFromLocation(_lat,_lon,1);
  6. for(int index=0; index<addresses.size(); ++index)
  7. {
  8. address = addresses.get(index);
  9. _homeAddress.append("Name: " + address.getLocality() + "\n");
  10. _homeAddress.append("Sub-Admin Ares: " + address.getSubAdminArea() + "\n");
  11. _homeAddress.append("Admin Area: " + address.getAdminArea() + "\n");
  12. _homeAddress.append("Country: " + address.getCountryName() + "\n");
  13. _homeAddress.append("Country Code: " + address.getCountryCode() + "\n");
  14. _homeAddress.append("Latitude: " + address.getLatitude() + "\n");
  15. _homeAddress.append("Longitude: " + address.getLongitude() + "\n\n");
  16. }
  17. }
  18. catch(Exception e){
  19. }

代码示例来源:origin: prabhat1707/EasyWayLocation

  1. public static String getAddress(Context context, Double latitude, Double longitude, boolean country, boolean fullAddress) {
  2. String add = "";
  3. Geocoder geoCoder = new Geocoder(((Activity) context).getBaseContext(), Locale.getDefault());
  4. try {
  5. List<Address> addresses = geoCoder.getFromLocation(latitude, longitude, 1);
  6. if (addresses.size() > 0) {
  7. if (country) {
  8. add = addresses.get(0).getCountryName();
  9. } else if (fullAddress) {
  10. add = addresses.get(0).getFeatureName() + "," + addresses.get(0).getSubLocality() + "," + addresses.get(0).getSubAdminArea() + "," + addresses.get(0).getPostalCode() + "," + addresses.get(0).getCountryName();
  11. } else {
  12. add = addresses.get(0).getLocality();
  13. }
  14. }
  15. } catch (IOException e) {
  16. e.printStackTrace();
  17. }
  18. return add.replaceAll(",null", "");
  19. }

代码示例来源:origin: WangDaYeeeeee/GeometricWeather

  1. result.city = addressList.get(0).getLocality();
  2. if (TextUtils.isEmpty(result.city)) {
  3. result.city = addressList.get(0).getSubAdminArea();

代码示例来源:origin: thuryn/your-local-weather

  1. public static String getCityAndCountryFromAddress(Address address) {
  2. if (address == null) {
  3. return "";
  4. }
  5. String geoCity;
  6. if((address.getLocality() != null) && !"".equals(address.getLocality())) {
  7. geoCity = address.getLocality();
  8. } else {
  9. geoCity = address.getSubAdminArea();
  10. }
  11. if (geoCity == null) {
  12. geoCity = "";
  13. }
  14. String geoCountryDistrict = null;
  15. if(address.getAdminArea() != null) {
  16. geoCountryDistrict = address.getAdminArea();
  17. }
  18. String geoDistrictOfCity = address.getSubLocality();
  19. String geoCountryName = address.getCountryName();
  20. if ((geoDistrictOfCity == null) || "".equals(geoDistrictOfCity) || geoCity.equalsIgnoreCase(geoDistrictOfCity)) {
  21. if ((geoCountryDistrict == null) || "".equals(geoCountryDistrict) || geoCity.equals(geoCountryDistrict)) {
  22. return formatLocalityToTwoLines((("".equals(geoCity))?"":(geoCity)) + (("".equals(geoCountryName))?"":(", " + geoCountryName)));
  23. }
  24. return formatLocalityToTwoLines((("".equals(geoCity))?"":(geoCity + ", ")) + geoCountryDistrict + (("".equals(geoCountryName))?"":(", " + geoCountryName)));
  25. }
  26. return formatLocalityToTwoLines((("".equals(geoCity))?"":(geoCity + " - ")) + geoDistrictOfCity + (("".equals(geoCountryName))?"":(", " + geoCountryName)));
  27. }

代码示例来源:origin: jareddlc/OpenFit

  1. cityName = addresses.get(0).getLocality();
  2. if (cityName == null) {
  3. cityName = addresses.get(0).getSubAdminArea();

代码示例来源:origin: jareddlc/OpenFit

  1. cityName = addresses.get(0).getLocality();
  2. if (cityName == null) {
  3. cityName = addresses.get(0).getSubAdminArea();

代码示例来源:origin: stackoverflow.com

  1. try {
  2. Geocoder geocoder = new Geocoder(this, Locale.getDefault());
  3. List<Address> addressList = geocoder.getFromLocation(latitude, longitude, 10);
  4. if (!addressList.isEmpty()) {
  5. for (Address address : addressList) {
  6. String result = address.getAdminArea() != null ? address.getAdminArea() : "?";
  7. result += " | ";
  8. result += address.getSubAdminArea() != null ? address.getSubAdminArea() : "?";
  9. result += " | ";
  10. result += address.getLocality() != null ? address.getLocality() : "?";
  11. result += " | ";
  12. result += address.getSubLocality() != null ? address.getSubLocality() : "?";
  13. result += " | ";
  14. result += address.getThoroughfare() != null ? address.getThoroughfare() : "?";
  15. result += " | ";
  16. result += address.getSubThoroughfare() != null ? address.getSubThoroughfare() : "?";
  17. Log.i(TAG, result);
  18. }
  19. }
  20. } catch (IOException e) {
  21. Log.e(TAG, "Failed Geocoding.");
  22. }

代码示例来源:origin: grzegorznittner/chanu

  1. private void updateLocation(Address address) {
  2. if (address != null) {
  3. Context context = mContext.getAndroidContext();
  4. String parts[] = {
  5. address.getAdminArea(),
  6. address.getSubAdminArea(),
  7. address.getLocality(),
  8. address.getSubLocality(),
  9. address.getThoroughfare(),
  10. address.getSubThoroughfare(),
  11. address.getPremises(),
  12. address.getPostalCode(),
  13. address.getCountryName()
  14. };
  15. String addressText = "";
  16. for (int i = 0; i < parts.length; i++) {
  17. if (parts[i] == null || parts[i].isEmpty()) continue;
  18. if (!addressText.isEmpty()) {
  19. addressText += ", ";
  20. }
  21. addressText += parts[i];
  22. }
  23. String text = String.format("%s : %s", DetailsHelper.getDetailsName(
  24. context, MediaDetails.INDEX_LOCATION), addressText);
  25. mListener.onAddressAvailable(text);
  26. }
  27. }

代码示例来源:origin: thuryn/your-local-weather

  1. public static PersistableBundle fromAddress(android.location.Address address) {
  2. if (address == null) {
  3. return null;
  4. }
  5. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
  6. PersistableBundle persistableBundle = new PersistableBundle();
  7. persistableBundle.putString("country", address.getLocale().getCountry());
  8. persistableBundle.putString("language", address.getLocale().getLanguage());
  9. persistableBundle.putString("variant", address.getLocale().getVariant());
  10. persistableBundle.putString("locality", address.getLocality());
  11. persistableBundle.putString("subLocality", address.getSubLocality());
  12. persistableBundle.putString("adminArea", address.getAdminArea());
  13. persistableBundle.putString("subAdminArea", address.getSubAdminArea());
  14. persistableBundle.putString("countryName", address.getCountryName());
  15. return persistableBundle;
  16. } else {
  17. return null;
  18. }
  19. }
  20. }

代码示例来源:origin: grzegorznittner/chanu

  1. writeUTF(dos, address.getLocality());
  2. writeUTF(dos, address.getAdminArea());
  3. writeUTF(dos, address.getSubAdminArea());

代码示例来源:origin: CUTR-at-USF/OpenTripPlanner-for-Android

  1. public CustomAddress(Address address) {
  2. super(address.getLocale());
  3. for (int i = 0; i <= address.getMaxAddressLineIndex(); i++){
  4. super.setAddressLine(i, address.getAddressLine(i));
  5. }
  6. super.setFeatureName(address.getFeatureName());
  7. super.setAdminArea(address.getAdminArea());
  8. super.setSubAdminArea(address.getSubAdminArea());
  9. super.setLocality(address.getLocality());
  10. super.setSubLocality(address.getSubLocality());
  11. super.setThoroughfare(address.getThoroughfare());
  12. super.setSubThoroughfare(address.getSubThoroughfare());
  13. super.setPostalCode(address.getPostalCode());
  14. super.setCountryCode(address.getCountryCode());
  15. super.setCountryName(address.getCountryName());
  16. super.setLatitude(address.getLatitude());
  17. super.setLongitude(address.getLongitude());
  18. super.setPhone(address.getPhone());
  19. super.setUrl(address.getUrl());
  20. super.setExtras(address.getExtras());
  21. }

相关文章