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

发布于 2024-08-17 21:16:17 字数 1082 浏览 5 评论 0原文

下面的代码非常适合在 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)

这是发生这种情况的代码片段:

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;
}

The code below works perfectly for real devices running on 1.5, 1.6
and 2.0 as well as the emulator running on 2.1.

However, executing it
on the Nexus One (running 2.1) raises an IOException:

java.io.IOException: Unable to parse response from server
at android.location.Geocoder.getFromLocation(Geocoder.java:124)

That's the code snippet where it happens:

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;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

两相知 2024-08-24 21:16:17

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

Hi I fell into the same problem and same situation. I got a Nexus One and I got a workaround to make addressList = geocoder.getFromLocation(myLatitude, myLongitude, 1); work.
You just have to restart your device. What I noticed is that Geocoder's getFromLocation method isn't aware of any change in Locale settings (in my case, what made the method stop working was the change of my default Locale).
After a restart everything worked. Anyone got a reasonably reason for this? (Sorry for the word game :-P )

微凉 2024-08-24 21:16:17

我使用的是 HTC Tmobile G2,在测试基于 GeoCoder 的功能时遇到了同样的问题。重新启动有所帮助,但当我的客户开始抱怨这一点时,这不是一个可接受的解决方案。如果这是某种缓存清除问题,那么我希望可以通过编程方式找到解决方法。

I'm using a HTC Tmobile G2, and I had the same problem while testing a GeoCoder based feature. A reboot helped, but that's not an acceptable solution when my customers start complaining about this. If this is some kind of cache clearing issue, then I hope a workaround can be put in place programmatically.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文