Android反向地理编码服务异常

时间:2012-12-13 13:05:18

标签: android reverse-geocoding

我正在尝试制作示例:http://developer.android.com/training/basics/location/geocoding.html#TaskReverseGeocoding

工作,但实际上我得到了

  

服务不可用例外

当试图检索地址时,我已经完成了这个并得到了API密钥和所有这些东西,但没有改变,它甚至在设备本身也不起作用!

1 个答案:

答案 0 :(得分:2)

    Geocoder geoCoder = new Geocoder(getBaseContext(), Locale.getDefault()); 
    try {
        List<Address> addresses = geoCoder.getFromLocation(latitude, longitude, 1);
        if (addresses.size() > 0) {
            String address = "";
            for (int index = 0; index < addresses.get(0).getMaxAddressLineIndex(); index++)
                address += addresses.get(0).getAddressLine(index) + " ";
            tv.setText(address);                   Toast.makeText(getApplicationContext(),""+address,Toast.LENGTH_SHORT).show();
            Log.v("AddressTag", address);
        }
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}