Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/313.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/199.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android,在Java中,将邮政编码转换为经度和纬度的最快、最有效的方法是什么?_Java_Android_Eclipse_Google Maps_Google Maps Api 3 - Fatal编程技术网

Android,在Java中,将邮政编码转换为经度和纬度的最快、最有效的方法是什么?

Android,在Java中,将邮政编码转换为经度和纬度的最快、最有效的方法是什么?,java,android,eclipse,google-maps,google-maps-api-3,Java,Android,Eclipse,Google Maps,Google Maps Api 3,我知道如何从经纬度坐标中获取邮政编码,但我不知道如何从邮政编码中获取反向(经纬度)我该怎么做 在安卓系统中 从经纬度坐标获取邮政编码的代码: Geocoder geoCoder = new Geocoder(getApplicationContext(), Locale.getDefault()); List<Address> address = null; if (geoCoder != null){ try { address= geoCoder.getFr

我知道如何从经纬度坐标中获取邮政编码,但我不知道如何从邮政编码中获取反向(经纬度)我该怎么做

在安卓系统中

从经纬度坐标获取邮政编码的代码:

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();
      }
Geocoder-Geocoder=new-Geocoder(getApplicationContext(),Locale.getDefault());
列表地址=空;
如果(地理编码器!=null){
试一试{
地址=地理编码器.getFromLocation(latPoint,lngPoint,1);
}捕获(IOE1异常){
//TODO自动生成的捕捉块
e1.printStackTrace();
}
if(address.size()>0){
字符串postCode=address.get(0.getPostalCode();
}

不幸的是,Geocoder只是一个门面。该实现依赖于设备,不是强制性的。如果谷歌自己的Geocoder服务是后端,则该方法可以足够可靠地工作,同时将邮政编码和国家/地区的组合指定为查询字符串,例如:

10007, USA
如果这对您不起作用,您可以使用来自的地理位置数据库。我刚刚尝试了一个基于邮政编码和国家名称的查询,并从他们那里收到了正确的结果


GeoNames有一个支持JSON和XML数据的web服务API,它们还为不同编程语言的各种客户端库提供下载链接。

您已经基本回答了自己的问题。Android Geocoder类可用于进行地理编码和反向地理编码。地址到latlon的转换参考to作为地理编码;latlon到地址的转换(如您的示例中)被称为反向地理编码。我修改了您的示例,以显示使用英国邮政编码的地理编码示例:

    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();
        }
    }
Geocoder-Geocoder=new-Geocoder(getActivity(),Locale.getDefault());
列表地址=空;
如果(地理编码器!=null){
试一试{
地址=地理编码器。getFromLocationName(“KT48LY”,10);
}捕获(IOE1异常){
e1.printStackTrace();
}
if(address.size()>0){
地址优先=地址。获取(0);
double lat=first.getLatitude();
double lon=first.getLongitude();
}
}