Android Geocoder返回空地址

Ani*_*kar 6 android geocoding

我正在尝试从Geocoder获取位置地址,我能够获得纬度和经度,但它返回的地址长度为零.

这是我的代码片段

            double longi = location.getLongitude();
            double latt = location.getLatitude();

            Geocoder geocoder = new Geocoder(getApplicationContext(), Locale.ENGLISH);

            String add="";
            try {


                List<Address> address = geocoder.getFromLocation(latt/1E6,longi/1E6, 1);


                System.out.println("in location listener "+address.size());


                int i=0;

                if(address.size()>0)
                {
                    for(i=0;i<address.get(0).getMaxAddressLineIndex();i++)
                    {
                        add += address.get(0).getAddressLine(i);
                    }


                    Toast toast  = new Toast(getApplicationContext());
                    toast.makeText(getApplicationContext(), add, Toast.LENGTH_LONG).show();
                }   

            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
Run Code Online (Sandbox Code Playgroud)

请帮我把它搞定.提前致谢!

vis*_*dra 5

如果平台中没有后端服务,则Geocoder查询方法将返回空列表.使用isPresent()方法确定是否存在Geocoder实现.

有关详细信息,请参阅Geocoder文档.

  • 我尝试过使用不同地址的`getFromLocationName()`.对于某些地址,我得到了结果但是对于某些地址,我得到一个大小为**0**的数组. (5认同)
  • 我已经检查了Geocoder.isPresent(),这个静态函数返回true.然而,我得到空地址列表 (2认同)