private String getAddress(String adressStr) throws IOException {
Geocoder geocoder = new Geocoder(this);
boolean falg = geocoder.isPresent();
KLog.e("the falg is " + falg);
StringBuilder stringBuilder = new StringBuilder();
try {
//根据经纬度获取地理位置信息
// List<Address> addresses = geocoder.getFromLocation(location.getLatitude(), location.getLongitude(), 1);
//根据地址获取地理位置信息
List<Address> addresses = geocoder.getFromLocationName(adressStr, 1);
if (addresses.size() > 0) {
Address address = addresses.get(0);
for (int i = 0; i < address.getMaxAddressLineIndex(); i++) {
stringBuilder.append(address.getAddressLine(i)).append("\n");
}
stringBuilder.append(address.getCountryName()).append("_");//国家
stringBuilder.append(address.getFeatureName()).append("_");//周边地址
stringBuilder.append(address.getLocality()).append("_");//市
stringBuilder.append(address.getPostalCode()).append("_");
stringBuilder.append(address.getCountryCode()).append("_");//国家编码
stringBuilder.append(address.getAdminArea()).append("_");//省份
stringBuilder.append(address.getSubAdminArea()).append("_");
stringBuilder.append(address.getThoroughfare()).append("_");//道路
stringBuilder.append(address.getSubLocality()).append("_");//香洲区
stringBuilder.append(address.getLatitude()).append("_");//经度
stringBuilder.append(address.getLongitude());//维度
KLog.e(stringBuilder.toString());
}
} catch (IOException e) {
// TODO Auto-generated catch block
Toast.makeText(this, "报错", Toast.LENGTH_LONG).show();
e.printStackTrace();
}
return stringBuilder.toString();
}
利用Geocoder来进行为位置转换经纬度
最新推荐文章于 2024-05-09 09:47:50 发布