本文整理汇总了Java中android.location.Address.getCountryName方法的典型用法代码示例。如果您正苦于以下问题:Java Address.getCountryName方法的具体用法?Java Address.getCountryName怎么用?Java Address.getCountryName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.location.Address
的用法示例。
在下文中一共展示了Address.getCountryName方法的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: getCountryName
import android.location.Address; //导入方法依赖的package包/类
/**
* Try to get CountryName
* @return null or postalCode
*/
public String getCountryName(Context context)
{
List<Address> addresses = getGeocoderAddress(context);
if (addresses != null && addresses.size() > 0)
{
Address address = addresses.get(0);
String countryName = address.getCountryName();
return countryName;
}
else
{
return null;
}
}
示例3: getLocalityNameEng
import android.location.Address; //导入方法依赖的package包/类
public static String getLocalityNameEng(Context context, LatLng latLng) {
Geocoder gcd = new Geocoder(context, Locale.US);
try {
List<Address> addresses = gcd.getFromLocation(latLng.latitude, latLng.longitude, 1);
if (addresses.size() > 0) {
Address address = addresses.get(0);
String name = address.getCountryName();
if (address.getLocality() != null)
name = address.getLocality();
return name;
}
} catch (IOException ex) {
Log.d(TAG, Log.getStackTraceString(ex));
}
return null;
}
示例4: getLocalityName
import android.location.Address; //导入方法依赖的package包/类
@Nullable
public static String getLocalityName(Context context, LatLng latLng) {
Geocoder gcd = new Geocoder(context, Locale.getDefault());
try {
List<Address> addresses = gcd.getFromLocation(latLng.latitude, latLng.longitude, 1);
if (addresses.size() > 0) {
Address address = addresses.get(0);
String name = address.getCountryName();
if (address.getLocality() != null)
name = address.getLocality() + ", " + name;
return name;
}
} catch (IOException ex) {
Log.d(TAG, Log.getStackTraceString(ex));
}
return null;
}
示例5: 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>";
}
示例6: 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;
}
示例7: getCountryName
import android.location.Address; //导入方法依赖的package包/类
/**
* 根据经纬度获取所在国家
*
* @param latitude 纬度
* @param longitude 经度
* @return 所在国家
*/
public static String getCountryName(double latitude, double longitude) {
Address address = getAddress(latitude, longitude);
return address == null ? "unknown" : address.getCountryName();
}