本文整理了Java中android.location.Address.getSubLocality()
方法的一些代码示例,展示了Address.getSubLocality()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Address.getSubLocality()
方法的具体详情如下:
包路径:android.location.Address
类名称:Address
方法名:getSubLocality
暂无
代码示例来源:origin: square/assertj-android
public AddressAssert hasSubLocality(String locality) {
isNotNull();
String actualLocality = actual.getSubLocality();
assertThat(actualLocality) //
.overridingErrorMessage("Expected sub-locality <%s> but was <%s>.", locality,
actualLocality) //
.isEqualTo(locality);
return this;
}
代码示例来源:origin: com.squareup.assertj/assertj-android
public AddressAssert hasSubLocality(String locality) {
isNotNull();
String actualLocality = actual.getSubLocality();
assertThat(actualLocality) //
.overridingErrorMessage("Expected sub-locality <%s> but was <%s>.", locality,
actualLocality) //
.isEqualTo(locality);
return this;
}
代码示例来源:origin: qqq3/good-weather
private void getAndWriteAddressFromGeocoder(String latitude, String longitude, SharedPreferences.Editor editor) {
Geocoder geocoder = new Geocoder(this, Locale.getDefault());
try {
String latitudeEn = latitude.replace(",", ".");
String longitudeEn = longitude.replace(",", ".");
List<Address> addresses = geocoder.getFromLocation(Double.parseDouble(latitudeEn), Double.parseDouble(longitudeEn), 1);
if ((addresses != null) && (addresses.size() > 0)) {
editor.putString(Constants.APP_SETTINGS_GEO_CITY, addresses.get(0).getLocality());
editor.putString(Constants.APP_SETTINGS_GEO_DISTRICT_OF_CITY, addresses.get(0).getSubLocality());
editor.putString(Constants.APP_SETTINGS_GEO_COUNTRY_NAME, addresses.get(0).getCountryName());
}
} catch (IOException | NumberFormatException ex) {
Log.e(TAG, "Unable to get address from latitude and longitude", ex);
}
}
代码示例来源:origin: Sishin/MapLocation
/**
* Sends a resultCode and message to the receiver.
*/
private void deliverResultToReceiver(int resultCode, String message, Address address) {
try {
Bundle bundle = new Bundle();
bundle.putString(AppUtils.LocationConstants.RESULT_DATA_KEY, message);
bundle.putString(AppUtils.LocationConstants.LOCATION_DATA_AREA, address.getSubLocality());
bundle.putString(AppUtils.LocationConstants.LOCATION_DATA_CITY, address.getLocality());
bundle.putString(AppUtils.LocationConstants.LOCATION_DATA_STREET, address.getAddressLine(0));
mReceiver.send(resultCode, bundle);
} catch (Exception e) {
e.printStackTrace();
}
}
代码示例来源:origin: prabhat1707/EasyWayLocation
public static String getAddress(Context context, Double latitude, Double longitude, boolean country, boolean fullAddress) {
String add = "";
Geocoder geoCoder = new Geocoder(((Activity) context).getBaseContext(), Locale.getDefault());
try {
List<Address> addresses = geoCoder.getFromLocation(latitude, longitude, 1);
if (addresses.size() > 0) {
if (country) {
add = addresses.get(0).getCountryName();
} else if (fullAddress) {
add = addresses.get(0).getFeatureName() + "," + addresses.get(0).getSubLocality() + "," + addresses.get(0).getSubAdminArea() + "," + addresses.get(0).getPostalCode() + "," + addresses.get(0).getCountryName();
} else {
add = addresses.get(0).getLocality();
}
}
} catch (IOException e) {
e.printStackTrace();
}
return add.replaceAll(",null", "");
}
代码示例来源:origin: WangDaYeeeeee/GeometricWeather
Result result = new Result();
result.district = addressList.get(0).getSubLocality();
result.city = addressList.get(0).getLocality();
if (TextUtils.isEmpty(result.city)) {
代码示例来源:origin: thuryn/your-local-weather
if (address.getLocality() != null) {
lastRowsFromDB.append(address.getLocality());
if (!address.getLocality().equals(address.getSubLocality())) {
lastRowsFromDB.append(" - ");
lastRowsFromDB.append(address.getSubLocality());
代码示例来源: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: 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());
}
内容来源于网络,如有侵权,请联系作者删除!