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

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

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

Address.getAdminArea介绍

暂无

代码示例

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

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

代码示例来源:origin: DaxiaK/MyDiary

  1. returnLocation.append(listAddresses.get(0).getCountryName());
  2. returnLocation.append(" ");
  3. returnLocation.append(listAddresses.get(0).getAdminArea());
  4. returnLocation.append(" ");
  5. returnLocation.append(listAddresses.get(0).getLocality());

代码示例来源:origin: DaxiaK/MyDiary

  1. returnLocation.append(listAddresses.get(0).getCountryName());
  2. returnLocation.append(" ");
  3. returnLocation.append(listAddresses.get(0).getAdminArea());
  4. returnLocation.append(" ");
  5. returnLocation.append(listAddresses.get(0).getLocality());

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

  1. Address address = addressList.get(0);
  2. String state = states.get(address.getAdminArea());
  3. result = address.getLocality() + ", " + state;

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

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

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

  1. private String getLocalityAdminForAddress(final Address addr, final boolean approxLocation) {
  2. if (addr == null)
  3. return "";
  4. String localityAdminStr = addr.getLocality();
  5. if (localityAdminStr != null && !("null".equals(localityAdminStr))) {
  6. if (approxLocation) {
  7. // TODO: Uncomment these lines as soon as we may translations
  8. // for Res.string.around.
  9. // localityAdminStr =
  10. // mContext.getResources().getString(Res.string.around) + " " +
  11. // localityAdminStr;
  12. }
  13. String adminArea = addr.getAdminArea();
  14. if (adminArea != null && adminArea.length() > 0) {
  15. localityAdminStr += ", " + adminArea;
  16. }
  17. return localityAdminStr;
  18. }
  19. return null;
  20. }

代码示例来源: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. Geocoder geocoder = new Geocoder(App.getContext(), Locale.US);
  2. List<Address> listOfAddress;
  3. try {
  4. listOfAddress = geocoder.getFromLocation(theLatitude, theLongitude, 1);
  5. if(listOfAddress != null && !listOfAddress.isEmpty()){
  6. Address address = listOfAddress.get(0);
  7. String country = address.getCountryCode();
  8. String adminArea= address.getAdminArea();
  9. String locality= address.getLocality();
  10. }
  11. } catch (IOException e) {
  12. e.printStackTrace();
  13. }

代码示例来源: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: ankitdubey021/GPSTracker

  1. private void fetchLocation(Location location) {
  2. List<Address> addresses;
  3. Geocoder geocoder = new Geocoder(ctx, Locale.getDefault());
  4. try {
  5. ADLocation adLocation=new ADLocation();
  6. addresses = geocoder.getFromLocation(location.getLatitude(), location.getLongitude(), 1);
  7. adLocation.address= addresses.get(0).getAddressLine(0); // If any additional address line present than only, check with max available address lines by getMaxAddressLineIndex()
  8. adLocation.city=addresses.get(0).getLocality();
  9. adLocation.state= addresses.get(0).getAdminArea();
  10. adLocation.country = addresses.get(0).getCountryName();
  11. adLocation.pincode= addresses.get(0).getPostalCode();
  12. adLocation.lat=location.getLatitude();
  13. adLocation.longi=location.getLongitude();
  14. locListener.whereIAM(adLocation);
  15. }catch (Exception e){
  16. e.printStackTrace();
  17. }
  18. }

代码示例来源:origin: zadr50/Gojek

  1. private String AddressFromLatLng(LatLng ll) {
  2. Geocoder geocoder;
  3. List<Address> addresses;
  4. geocoder = new Geocoder(this, Locale.getDefault());
  5. String address="";
  6. try {
  7. addresses = geocoder.getFromLocation(ll.latitude, ll.longitude, 1); // Here 1 represent max location result to returned, by documents it recommended 1 to 5
  8. if(addresses.size()>0) {
  9. address = addresses.get(0).getAddressLine(0); // If any additional address line present than only, check with max available address lines by getMaxAddressLineIndex()
  10. String city = addresses.get(0).getLocality();
  11. String state = addresses.get(0).getAdminArea();
  12. String country = addresses.get(0).getCountryName();
  13. String postalCode = addresses.get(0).getPostalCode();
  14. String knownName = addresses.get(0).getFeatureName();
  15. }
  16. } catch (IOException e) {
  17. e.printStackTrace();
  18. }
  19. return address;
  20. }

代码示例来源:origin: zadr50/Gojek

  1. private String AddressFromLatLng(LatLng myLatLng) {
  2. Geocoder geocoder;
  3. List<Address> addresses;
  4. geocoder = new Geocoder(this, Locale.getDefault());
  5. String address="Current Location";
  6. try {
  7. addresses = geocoder.getFromLocation(myLatLng.latitude, myLatLng.longitude, 1); // Here 1 represent max location result to returned, by documents it recommended 1 to 5
  8. if(addresses.size()>0) {
  9. address = addresses.get(0).getAddressLine(0); // If any additional address line present than only, check with max available address lines by getMaxAddressLineIndex()
  10. String city = addresses.get(0).getLocality();
  11. String state = addresses.get(0).getAdminArea();
  12. String country = addresses.get(0).getCountryName();
  13. String postalCode = addresses.get(0).getPostalCode();
  14. String knownName = addresses.get(0).getFeatureName();
  15. }
  16. } catch (IOException e) {
  17. e.printStackTrace();
  18. }
  19. return address;
  20. }

代码示例来源:origin: kollerlukas/Camera-Roll-Android-App

  1. valueText = address.getLocality();
  2. if (address.getAdminArea() != null) {
  3. if (valueText != null) {
  4. valueText += ", " + address.getAdminArea();
  5. } else {
  6. valueText = address.getAdminArea();

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

  1. result.city = addressList.get(0).getSubAdminArea();
  2. result.province = addressList.get(0).getAdminArea();
  3. result.country = addressList.get(0).getCountryName();

代码示例来源: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).getAdminArea();
  2. StateName = addresses.get(0).getAdminArea();
  3. CountryName = addresses.get(0).getCountryName();
  4. CountryCode = addresses.get(0).getCountryCode();

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

相关文章