我知道如何从经度和纬度坐标获取邮政编码,但我不知道如何获取相反的信息(从邮政编码获取经度和纬度),我该怎么做?
在Android中
从经度和纬度坐标获取邮政编码的代码:
Geocoder geoCoder = new Geocoder(getApplicationContext(), Locale.getDefault());
List<Address> address = null;
if (geoCoder != null){
try {
address= geoCoder.getFromLocation(latPoint, lngPoint, 1);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
if (address.size()> 0){
String postCode = address.get(0).getPostalCode();
}
最佳答案
你已经基本回答了你自己的问题。 Android Geocoder 类可用于进行地理编码和反向地理编码。地址到纬度的转换称为地理编码;纬度到地址的转换(如您的示例中)称为反向地理编码。我已修改您的示例以显示使用英国邮政编码的地理编码示例:
Geocoder geoCoder = new Geocoder(getActivity(), Locale.getDefault());
List<Address> address = null;
if (geoCoder != null) {
try {
address = geoCoder.getFromLocationName("KT48LY", 10);
} catch (IOException e1) {
e1.printStackTrace();
}
if (address.size() > 0) {
Address first = address.get(0);
double lat = first.getLatitude();
double lon = first.getLongitude();
}
}
关于java - Android,在 Java 中将邮政编码转换为经度和纬度的最快、最有效的方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21834877/