本文整理匯總了Java中android.location.Address.getAdminArea方法的典型用法代碼示例。如果您正苦於以下問題:Java Address.getAdminArea方法的具體用法?Java Address.getAdminArea怎麽用?Java Address.getAdminArea使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.location.Address
的用法示例。
在下文中一共展示了Address.getAdminArea方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getAddress
import android.location.Address; //導入方法依賴的package包/類
public String getAddress(Context context, double lat, double lng) {
Geocoder geocoder = new Geocoder(context, Locale.getDefault());
try {
List<Address> addresses = geocoder.getFromLocation(lat, lng, 1);
Address obj = addresses.get(0);
String add = obj.getAddressLine(0);
add = add + "," + obj.getAdminArea();
add = add + "," + obj.getCountryName();
return add;
} catch (IOException e) {
e.printStackTrace();
Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show();
return null;
}
}
示例2: getLocalityAdminForAddress
import android.location.Address; //導入方法依賴的package包/類
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;
}
示例3: getSimplifiedAddress
import android.location.Address; //導入方法依賴的package包/類
/**
* @param latitude latitude of address
* @param longitude longitude of address
* @return simplified address of location
*/
public String getSimplifiedAddress(double latitude, double longitude) {
String location = "";
try {
Geocoder geocoder = new Geocoder(mContext, Locale.getDefault());
List<Address> addresses = geocoder.getFromLocation(latitude, longitude, 1);
if (addresses.size() > 0) {
Address address = addresses.get(0);
String admin = address.getAdminArea();
String subLocality = address.getSubLocality();
String locality = address.getLocality();
if (admin.length() > 10) {
admin = admin.substring(0, 10) + "..";
}
if (locality != null && subLocality != null) {
location = subLocality + "," + locality;
} else if (subLocality != null) {
location = subLocality + "," + admin;
} else {
location = locality + "," + admin;
}
}
} catch (IOException e) {
e.printStackTrace();
}
return location;
}
示例4: getCompleteAddress
import android.location.Address; //導入方法依賴的package包/類
/**
* @param latitude latitude of address
* @param longitude longitude of address
* @return complete address of location
*/
public String getCompleteAddress(double latitude, double longitude) {
String location = "";
try {
Geocoder geocoder = new Geocoder(mContext, Locale.getDefault());
List<Address> addresses = geocoder.getFromLocation(latitude, longitude, 1);
if (addresses.size() > 0) {
Address address = addresses.get(0);
String state, city, zip, street;
if (address.getAdminArea() != null) {
state = address.getAdminArea();
} else {
state = "";
}
if (address.getLocality() != null) {
city = address.getLocality();
} else {
city = "";
}
if (address.getPostalCode() != null) {
zip = address.getPostalCode();
} else {
zip = "";
}
if (address.getThoroughfare() != null) {
street = address.getSubLocality() + "," + address.getThoroughfare();
} else {
street = address.getSubLocality() + "," + address.getFeatureName();
}
location = street + "," + city + "," + zip + "," + state;
}
} catch (IOException e) {
e.printStackTrace();
}
return location;
}
示例5: locationToAddress
import android.location.Address; //導入方法依賴的package包/類
public boolean locationToAddress(double latitude, double longitude) {
Geocoder geocoder = new Geocoder(this.context, Locale.getDefault());
try {
List<Address> addresses = geocoder.getFromLocation(latitude, longitude, 1);
if (addresses != null) {
Address returnedAddress = addresses.get(0);
StringBuilder strReturnedAddress = new StringBuilder("");
locationInfo.clear();
String city = returnedAddress.getAdminArea();
if(city==null) city = returnedAddress.getLocality();
locationInfo.put("country", returnedAddress.getCountryName());
locationInfo.put("countrycode", returnedAddress.getCountryCode().toLowerCase());
locationInfo.put("latitude", ""+returnedAddress.getLatitude());
locationInfo.put("longitude", ""+returnedAddress.getLongitude());
if(city!=null)locationInfo.put("city", ""+city);
String address = "";
for (int i = 0; i < returnedAddress.getMaxAddressLineIndex(); i++) {
address = address + returnedAddress.getAddressLine(i) + "\n";
}
locationInfo.put("address", address);
return true;
} else {
}
} catch (Exception e) {
}
return false;
}
示例6: getAddressHTMLText
import android.location.Address; //導入方法依賴的package包/類
@android.support.annotation.NonNull
public String getAddressHTMLText(Address addressObj) {
String address = addressObj.getAddressLine(0); // If any additional address line present than only, check with max available address lines by getMaxAddressLineIndex()
String city = addressObj.getLocality();
String state = addressObj.getAdminArea();
String country = addressObj.getCountryName();
String postalCode = addressObj.getPostalCode();
String part1 = addressObj.getFeatureName();
String part2 = address + ", " + city + ", " + state + ", " + country + ", " + postalCode;
return "<b>" + part1 + "</b><label style='color:#ccc'> <br>" + part2 + "</label>";
}
示例7: getAddressString
import android.location.Address; //導入方法依賴的package包/類
@android.support.annotation.NonNull
public String getAddressString(Address addressObj) {
String address = addressObj.getAddressLine(0); // If any additional address line present than only, check with max available address lines by getMaxAddressLineIndex()
String city = addressObj.getLocality();
String state = addressObj.getAdminArea();
String country = addressObj.getCountryName();
String postalCode = addressObj.getPostalCode();
return address + ", " + city + ", " + state + ", " + country + ", " + postalCode;
}