为什么 Android Geocoder 会抛出“服务不可用”的错误消息?例外?
该应用使用 Geocoder 对象。它在我的库存 Froyo Nexus One 上运行良好。但随后我在不同的设备上运行完全相同的应用程序(Advent Vega 10 英寸平板电脑也运行 Froyo),然后出现此异常:服务不可用。我使用的方法是 getFromLocationName()
,我正在针对 Android 1.6 Google API 进行构建,
我知道在模拟器上会引发此异常,但我怀疑这是不同的,为什么它会在一台设备上引发。运行 Froyo 而不是其他应用程序?
该应用程序是一个位置应用程序,并且由于平板电脑没有 GPS 或移动网络,在 Wi-Fi 连接无法提供位置的情况下,用户必须手动指定它,因此无法能够使用 Geocoder 对象是个坏消息,
我可以为用户添加一种在地图上选择位置的方法,但这可能并不理想,我可以直接使用 Google Maps API,但我很想了解其本质。首先解决这个问题,
希望在未来的版本中 Android 能够为非地理编码器设备提供操作系统级别的“默认位置”,这样位置感知应用程序就可以在 Google 等设备上开箱即用。电视。
The app uses the Geocoder object. It works fine on my stock Froyo Nexus One. But then I run the exact same app on a different device (an Advent Vega 10" tablet also running Froyo) and I get this exception: Service not Available. The method I'm using is getFromLocationName()
, I'm building against the Android 1.6 Google API.
I'm aware of an issue where this exception is thrown on the emulator, but I suspect this is different. Why would it be thrown on one device running Froyo but not another?
The app is a location app, and as the tablet has no GPS or mobile network, in a scenario where the Wi-Fi connection doesn't provide a location, the user must manually specify it, so not being able to use the Geocoder object is bad news.
I could add a way for the user to select the location on a map, but it's not ideal. Possibly I could use the Google Maps API directly, but I'm keen to understand the nature of the issue first as would be nice to have an easier solution.
Hopefully in a future release Android will include an OS-level "default location" for non-Geocoder devices, so location-aware apps work out of the box on devices like Google TV.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
我请 Google 的 Reto Meier 确认我的理论是否正确,他说“正确。地理编码器是 Google API 插件的一部分,而不是 AOSP 的一部分。”
因此,任何不支持该理论的设备不附带 Play 商店、GMail 应用程序等……也将缺少地理编码器后端。
I asked Google's Reto Meier to confirm my theory was correct and he said "Correct. The Geocoder is part of the Google API add-on that isn't part of the AOSP."
So any device that doesn't come with the Play Store, GMail apps etc… will also be missing the Geocoder back-end.
似乎有此问题的另一种可能的解决方法< /strong>,不幸的是,它被标记为重复问题,因此可能会被错过。本质上,重新启动设备即可解决问题。请注意,我将其称为“解决方法”,而不是“解决方案”。 :(
There seems to be another possible workaround for this problem, which is unfortunately marked as a duplicate question, and therefore might be missed. Essentially, a reboot of the device clears up the problem. Note I called it a "workaround" and not a "solution". :(
对于那些寻找替代方案的人来说,希望我在另一篇文章中的回答有用。
当发现地理编码错误时,您可以使用 Google Geocoding API。
更多代码=> 使用 json 获取当前位置
For those who searching alternative, Hopefully, my answer in another post is useful.
You can use Google Geocoding API when caught error in geocoding.
For more code => Get current location using json
有些设备不支持地理编码器,因此您需要做的是创建自己的地理编码器。
基本上,您需要创建一个异步任务来向 google 请求地址并处理 json 响应。
使用 aquery,我做了这样的事情:
Some devices do not have suport for Geocoder, so what you need to do is create your own geocoder.
Basicaly you need create a async task to request google for the address and treat the json response.
Using aquery, i do something like this:
浪费了几个小时后,我得到了一个最简单的解决方案。
我刚刚重新启动了我的设备,它就开始工作了。
看来,该问题是由于某些操作系统级别的缓存问题造成的。希望它也适用于您..
After wasting several hours, I got a simplest solution.
I Just restarted my device, and it started working.
It seems, the problem is due to some OS level caching problem. Hope it will also work for your..
我有同样的问题。我使用了以下功能。
笔记:
I had the same issue. I used the following function.
Note: