本文整理了Java中android.location.Address.getAdminArea()
方法的一些代码示例,展示了Address.getAdminArea()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Address.getAdminArea()
方法的具体详情如下:
包路径:android.location.Address
类名称:Address
方法名:getAdminArea
暂无
代码示例来源:origin: square/assertj-android
public AddressAssert hasAdminArea(String area) {
isNotNull();
String actualArea = actual.getAdminArea();
assertThat(actualArea) //
.overridingErrorMessage("Expected admin area <%s> but was <%s>.", area, actualArea) //
.isEqualTo(area);
return this;
}
代码示例来源:origin: DaxiaK/MyDiary
returnLocation.append(listAddresses.get(0).getCountryName());
returnLocation.append(" ");
returnLocation.append(listAddresses.get(0).getAdminArea());
returnLocation.append(" ");
returnLocation.append(listAddresses.get(0).getLocality());
代码示例来源:origin: DaxiaK/MyDiary
returnLocation.append(listAddresses.get(0).getCountryName());
returnLocation.append(" ");
returnLocation.append(listAddresses.get(0).getAdminArea());
returnLocation.append(" ");
returnLocation.append(listAddresses.get(0).getLocality());
代码示例来源:origin: stackoverflow.com
Address address = addressList.get(0);
String state = states.get(address.getAdminArea());
result = address.getLocality() + ", " + state;
代码示例来源:origin: com.squareup.assertj/assertj-android
public AddressAssert hasAdminArea(String area) {
isNotNull();
String actualArea = actual.getAdminArea();
assertThat(actualArea) //
.overridingErrorMessage("Expected admin area <%s> but was <%s>.", area, actualArea) //
.isEqualTo(area);
return this;
}
代码示例来源:origin: grzegorznittner/chanu
private String getLocalityAdminForAddress(final Address addr, final boolean approxLocation) {
if (addr == null)
return "";
String localityAdminStr = addr.getLocality();
if (localityAdminStr != null && !("null".equals(localityAdminStr))) {
if (approxLocation) {
// TODO: Uncomment these lines as soon as we may translations
// for Res.string.around.
// localityAdminStr =
// mContext.getResources().getString(Res.string.around) + " " +
// localityAdminStr;
}
String adminArea = addr.getAdminArea();
if (adminArea != null && adminArea.length() > 0) {
localityAdminStr += ", " + adminArea;
}
return localityAdminStr;
}
return null;
}
代码示例来源:origin: stackoverflow.com
Geocoder gc = new Geocoder(context);
if(gc.isPresent()){
List<Address> list = gc.getFromLocation(37.42279, -122.08506,1);
Address address = list.get(0);
StringBuffer str = new StringBuffer();
str.append("Name: " + address.getLocality() + "\n");
str.append("Sub-Admin Ares: " + address.getSubAdminArea() + "\n");
str.append("Admin Area: " + address.getAdminArea() + "\n");
str.append("Country: " + address.getCountryName() + "\n");
str.append("Country Code: " + address.getCountryCode() + "\n");
String strAddress = str.toString();
}
代码示例来源:origin: stackoverflow.com
Geocoder geocoder = new Geocoder(App.getContext(), Locale.US);
List<Address> listOfAddress;
try {
listOfAddress = geocoder.getFromLocation(theLatitude, theLongitude, 1);
if(listOfAddress != null && !listOfAddress.isEmpty()){
Address address = listOfAddress.get(0);
String country = address.getCountryCode();
String adminArea= address.getAdminArea();
String locality= address.getLocality();
}
} catch (IOException e) {
e.printStackTrace();
}
代码示例来源:origin: stackoverflow.com
StringBuilder _homeAddress = null;
try{
_homeAddress = new StringBuilder();
Address address = null;
List<Address> addresses = _coder.getFromLocation(_lat,_lon,1);
for(int index=0; index<addresses.size(); ++index)
{
address = addresses.get(index);
_homeAddress.append("Name: " + address.getLocality() + "\n");
_homeAddress.append("Sub-Admin Ares: " + address.getSubAdminArea() + "\n");
_homeAddress.append("Admin Area: " + address.getAdminArea() + "\n");
_homeAddress.append("Country: " + address.getCountryName() + "\n");
_homeAddress.append("Country Code: " + address.getCountryCode() + "\n");
_homeAddress.append("Latitude: " + address.getLatitude() + "\n");
_homeAddress.append("Longitude: " + address.getLongitude() + "\n\n");
}
}
catch(Exception e){
}
代码示例来源:origin: ankitdubey021/GPSTracker
private void fetchLocation(Location location) {
List<Address> addresses;
Geocoder geocoder = new Geocoder(ctx, Locale.getDefault());
try {
ADLocation adLocation=new ADLocation();
addresses = geocoder.getFromLocation(location.getLatitude(), location.getLongitude(), 1);
adLocation.address= addresses.get(0).getAddressLine(0); // If any additional address line present than only, check with max available address lines by getMaxAddressLineIndex()
adLocation.city=addresses.get(0).getLocality();
adLocation.state= addresses.get(0).getAdminArea();
adLocation.country = addresses.get(0).getCountryName();
adLocation.pincode= addresses.get(0).getPostalCode();
adLocation.lat=location.getLatitude();
adLocation.longi=location.getLongitude();
locListener.whereIAM(adLocation);
}catch (Exception e){
e.printStackTrace();
}
}
代码示例来源:origin: zadr50/Gojek
private String AddressFromLatLng(LatLng ll) {
Geocoder geocoder;
List<Address> addresses;
geocoder = new Geocoder(this, Locale.getDefault());
String address="";
try {
addresses = geocoder.getFromLocation(ll.latitude, ll.longitude, 1); // Here 1 represent max location result to returned, by documents it recommended 1 to 5
if(addresses.size()>0) {
address = addresses.get(0).getAddressLine(0); // If any additional address line present than only, check with max available address lines by getMaxAddressLineIndex()
String city = addresses.get(0).getLocality();
String state = addresses.get(0).getAdminArea();
String country = addresses.get(0).getCountryName();
String postalCode = addresses.get(0).getPostalCode();
String knownName = addresses.get(0).getFeatureName();
}
} catch (IOException e) {
e.printStackTrace();
}
return address;
}
代码示例来源:origin: zadr50/Gojek
private String AddressFromLatLng(LatLng myLatLng) {
Geocoder geocoder;
List<Address> addresses;
geocoder = new Geocoder(this, Locale.getDefault());
String address="Current Location";
try {
addresses = geocoder.getFromLocation(myLatLng.latitude, myLatLng.longitude, 1); // Here 1 represent max location result to returned, by documents it recommended 1 to 5
if(addresses.size()>0) {
address = addresses.get(0).getAddressLine(0); // If any additional address line present than only, check with max available address lines by getMaxAddressLineIndex()
String city = addresses.get(0).getLocality();
String state = addresses.get(0).getAdminArea();
String country = addresses.get(0).getCountryName();
String postalCode = addresses.get(0).getPostalCode();
String knownName = addresses.get(0).getFeatureName();
}
} catch (IOException e) {
e.printStackTrace();
}
return address;
}
代码示例来源:origin: kollerlukas/Camera-Roll-Android-App
valueText = address.getLocality();
if (address.getAdminArea() != null) {
if (valueText != null) {
valueText += ", " + address.getAdminArea();
} else {
valueText = address.getAdminArea();
代码示例来源:origin: WangDaYeeeeee/GeometricWeather
result.city = addressList.get(0).getSubAdminArea();
result.province = addressList.get(0).getAdminArea();
result.country = addressList.get(0).getCountryName();
代码示例来源:origin: thuryn/your-local-weather
public static String getCityAndCountryFromAddress(Address address) {
if (address == null) {
return "";
}
String geoCity;
if((address.getLocality() != null) && !"".equals(address.getLocality())) {
geoCity = address.getLocality();
} else {
geoCity = address.getSubAdminArea();
}
if (geoCity == null) {
geoCity = "";
}
String geoCountryDistrict = null;
if(address.getAdminArea() != null) {
geoCountryDistrict = address.getAdminArea();
}
String geoDistrictOfCity = address.getSubLocality();
String geoCountryName = address.getCountryName();
if ((geoDistrictOfCity == null) || "".equals(geoDistrictOfCity) || geoCity.equalsIgnoreCase(geoDistrictOfCity)) {
if ((geoCountryDistrict == null) || "".equals(geoCountryDistrict) || geoCity.equals(geoCountryDistrict)) {
return formatLocalityToTwoLines((("".equals(geoCity))?"":(geoCity)) + (("".equals(geoCountryName))?"":(", " + geoCountryName)));
}
return formatLocalityToTwoLines((("".equals(geoCity))?"":(geoCity + ", ")) + geoCountryDistrict + (("".equals(geoCountryName))?"":(", " + geoCountryName)));
}
return formatLocalityToTwoLines((("".equals(geoCity))?"":(geoCity + " - ")) + geoDistrictOfCity + (("".equals(geoCountryName))?"":(", " + geoCountryName)));
}
代码示例来源:origin: jareddlc/OpenFit
cityName = addresses.get(0).getAdminArea();
StateName = addresses.get(0).getAdminArea();
CountryName = addresses.get(0).getCountryName();
CountryCode = addresses.get(0).getCountryCode();
代码示例来源:origin: stackoverflow.com
try {
Geocoder geocoder = new Geocoder(this, Locale.getDefault());
List<Address> addressList = geocoder.getFromLocation(latitude, longitude, 10);
if (!addressList.isEmpty()) {
for (Address address : addressList) {
String result = address.getAdminArea() != null ? address.getAdminArea() : "?";
result += " | ";
result += address.getSubAdminArea() != null ? address.getSubAdminArea() : "?";
result += " | ";
result += address.getLocality() != null ? address.getLocality() : "?";
result += " | ";
result += address.getSubLocality() != null ? address.getSubLocality() : "?";
result += " | ";
result += address.getThoroughfare() != null ? address.getThoroughfare() : "?";
result += " | ";
result += address.getSubThoroughfare() != null ? address.getSubThoroughfare() : "?";
Log.i(TAG, result);
}
}
} catch (IOException e) {
Log.e(TAG, "Failed Geocoding.");
}
代码示例来源:origin: grzegorznittner/chanu
private void updateLocation(Address address) {
if (address != null) {
Context context = mContext.getAndroidContext();
String parts[] = {
address.getAdminArea(),
address.getSubAdminArea(),
address.getLocality(),
address.getSubLocality(),
address.getThoroughfare(),
address.getSubThoroughfare(),
address.getPremises(),
address.getPostalCode(),
address.getCountryName()
};
String addressText = "";
for (int i = 0; i < parts.length; i++) {
if (parts[i] == null || parts[i].isEmpty()) continue;
if (!addressText.isEmpty()) {
addressText += ", ";
}
addressText += parts[i];
}
String text = String.format("%s : %s", DetailsHelper.getDetailsName(
context, MediaDetails.INDEX_LOCATION), addressText);
mListener.onAddressAvailable(text);
}
}
代码示例来源:origin: thuryn/your-local-weather
public static PersistableBundle fromAddress(android.location.Address address) {
if (address == null) {
return null;
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
PersistableBundle persistableBundle = new PersistableBundle();
persistableBundle.putString("country", address.getLocale().getCountry());
persistableBundle.putString("language", address.getLocale().getLanguage());
persistableBundle.putString("variant", address.getLocale().getVariant());
persistableBundle.putString("locality", address.getLocality());
persistableBundle.putString("subLocality", address.getSubLocality());
persistableBundle.putString("adminArea", address.getAdminArea());
persistableBundle.putString("subAdminArea", address.getSubAdminArea());
persistableBundle.putString("countryName", address.getCountryName());
return persistableBundle;
} else {
return null;
}
}
}
代码示例来源:origin: CUTR-at-USF/OpenTripPlanner-for-Android
public CustomAddress(Address address) {
super(address.getLocale());
for (int i = 0; i <= address.getMaxAddressLineIndex(); i++){
super.setAddressLine(i, address.getAddressLine(i));
}
super.setFeatureName(address.getFeatureName());
super.setAdminArea(address.getAdminArea());
super.setSubAdminArea(address.getSubAdminArea());
super.setLocality(address.getLocality());
super.setSubLocality(address.getSubLocality());
super.setThoroughfare(address.getThoroughfare());
super.setSubThoroughfare(address.getSubThoroughfare());
super.setPostalCode(address.getPostalCode());
super.setCountryCode(address.getCountryCode());
super.setCountryName(address.getCountryName());
super.setLatitude(address.getLatitude());
super.setLongitude(address.getLongitude());
super.setPhone(address.getPhone());
super.setUrl(address.getUrl());
super.setExtras(address.getExtras());
}
内容来源于网络,如有侵权,请联系作者删除!