Android:Nexus One - Geocoder导致IOException - 与其他设备和模拟器完美配合

znq*_*znq 6 android geocoding ioexception nexus-one

下面的代码适用于在1.5,1.6和2.0上运行的实际设备以及在2.1上运行的仿真器.

但是,在Nexus One(运行2.1)上执行它会引发IOException:

java.io.IOException: Unable to parse response from server
at android.location.Geocoder.getFromLocation(Geocoder.java:124)
Run Code Online (Sandbox Code Playgroud)

这是它发生的代码片段:

Double myLatitude = AppObject.myLocation.getLatitude();
Double myLongitude = AppObject.myLocation.getLongitude();
DEBUG.i(TAG, "My location: " + myLatitude + " | " + myLongitude);
Geocoder geocoder = new Geocoder(MainActivity.this);
java.util.List<Address> addressList;
try {
    addressList = geocoder.getFromLocation(myLatitude, myLongitude, 5);
    if(addressList!=null && addressList.size()>0) {
        currentAddress = new String();
        DEBUG.i(TAG,addressList.get(0).toString());
        currentAddress = addressList.get(0).getAddressLine(0) + ", "
        + addressList.get(0).getAddressLine(1) + ", "
        + addressList.get(0).getAddressLine(2); 

    }
    return true;

} catch (IOException e) {
    e.printStackTrace();
    return false;
}
Run Code Online (Sandbox Code Playgroud)

小智 1

嗨,我遇到了同样的问题和同样的情况。我有一台 Nexus One,并且找到了一个解决方法来工作addressList = geocoder.getFromLocation(myLatitude, myLongitude, 1);。您只需重新启动您的设备即可。我注意到 Geocoder 的 getFromLocation 方法不知道区域设置的任何更改(在我的例子中,导致该方法停止工作的是我的默认区域设置的更改)。重新启动后一切正常。有人对此有合理的理由吗?(抱歉这个文字游戏:-P)