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

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

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

Address.getSubLocality介绍

暂无

代码示例

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

  1. public AddressAssert hasSubLocality(String locality) {
  2. isNotNull();
  3. String actualLocality = actual.getSubLocality();
  4. assertThat(actualLocality) //
  5. .overridingErrorMessage("Expected sub-locality <%s> but was <%s>.", locality,
  6. actualLocality) //
  7. .isEqualTo(locality);
  8. return this;
  9. }

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

  1. public AddressAssert hasSubLocality(String locality) {
  2. isNotNull();
  3. String actualLocality = actual.getSubLocality();
  4. assertThat(actualLocality) //
  5. .overridingErrorMessage("Expected sub-locality <%s> but was <%s>.", locality,
  6. actualLocality) //
  7. .isEqualTo(locality);
  8. return this;
  9. }

代码示例来源:origin: qqq3/good-weather

  1. private void getAndWriteAddressFromGeocoder(String latitude, String longitude, SharedPreferences.Editor editor) {
  2. Geocoder geocoder = new Geocoder(this, Locale.getDefault());
  3. try {
  4. String latitudeEn = latitude.replace(",", ".");
  5. String longitudeEn = longitude.replace(",", ".");
  6. List<Address> addresses = geocoder.getFromLocation(Double.parseDouble(latitudeEn), Double.parseDouble(longitudeEn), 1);
  7. if ((addresses != null) && (addresses.size() > 0)) {
  8. editor.putString(Constants.APP_SETTINGS_GEO_CITY, addresses.get(0).getLocality());
  9. editor.putString(Constants.APP_SETTINGS_GEO_DISTRICT_OF_CITY, addresses.get(0).getSubLocality());
  10. editor.putString(Constants.APP_SETTINGS_GEO_COUNTRY_NAME, addresses.get(0).getCountryName());
  11. }
  12. } catch (IOException | NumberFormatException ex) {
  13. Log.e(TAG, "Unable to get address from latitude and longitude", ex);
  14. }
  15. }

代码示例来源:origin: Sishin/MapLocation

  1. /**
  2. * Sends a resultCode and message to the receiver.
  3. */
  4. private void deliverResultToReceiver(int resultCode, String message, Address address) {
  5. try {
  6. Bundle bundle = new Bundle();
  7. bundle.putString(AppUtils.LocationConstants.RESULT_DATA_KEY, message);
  8. bundle.putString(AppUtils.LocationConstants.LOCATION_DATA_AREA, address.getSubLocality());
  9. bundle.putString(AppUtils.LocationConstants.LOCATION_DATA_CITY, address.getLocality());
  10. bundle.putString(AppUtils.LocationConstants.LOCATION_DATA_STREET, address.getAddressLine(0));
  11. mReceiver.send(resultCode, bundle);
  12. } catch (Exception e) {
  13. e.printStackTrace();
  14. }
  15. }

代码示例来源: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 result = new Result();
  2. result.district = addressList.get(0).getSubLocality();
  3. result.city = addressList.get(0).getLocality();
  4. if (TextUtils.isEmpty(result.city)) {

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

  1. if (address.getLocality() != null) {
  2. lastRowsFromDB.append(address.getLocality());
  3. if (!address.getLocality().equals(address.getSubLocality())) {
  4. lastRowsFromDB.append(" - ");
  5. lastRowsFromDB.append(address.getSubLocality());

代码示例来源: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: 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: 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. }

相关文章