为什么 Android Geocoder 会抛出“服务不可用”的错误消息?例外?

发布于 2024-10-13 03:01:05 字数 651 浏览 10 评论 0原文

该应用使用 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 技术交流群。

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

发布评论

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

评论(6

骷髅 2024-10-20 03:01:05

我请 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.

时间你老了 2024-10-20 03:01:05

似乎有此问题的另一种可能的解决方法< /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". :(

沫尐诺 2024-10-20 03:01:05

对于那些寻找替代方案的人来说,希望我在另一篇文章中的回答有用。
当发现地理编码错误时,您可以使用 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

夏の忆 2024-10-20 03:01:05

有些设备不支持地理编码器,因此您需要做的是创建自己的地理编码器。

基本上,您需要创建一个异步任务来向 google 请求地址并处理 json 响应。

使用 aquery,我做了这样的事情:

public void asyncJson(String address){
        address = address.replace(" ", "+");

        String url = "http://maps.googleapis.com/maps/api/geocode/json?address="+ address +"&sensor=true";

        aq.ajax(url, JSONObject.class, new AjaxCallback<JSONObject>() {

                @Override
                public void callback(String url, JSONObject json, AjaxStatus status) {                        

                        if(json != null){

                                 //here you work with the response json
                                 JSONArray results = json.getJSONArray("results");                               
                                Toast.makeText(context, results.getJSONObject(1).getString("formatted_address"));

                        }else{                                
                                //ajax error, show error code
                                Toast.makeText(aq.getContext(), "Error:" + status.getCode(), Toast.LENGTH_LONG).show();
                        }
                }
        });        
}

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:

public void asyncJson(String address){
        address = address.replace(" ", "+");

        String url = "http://maps.googleapis.com/maps/api/geocode/json?address="+ address +"&sensor=true";

        aq.ajax(url, JSONObject.class, new AjaxCallback<JSONObject>() {

                @Override
                public void callback(String url, JSONObject json, AjaxStatus status) {                        

                        if(json != null){

                                 //here you work with the response json
                                 JSONArray results = json.getJSONArray("results");                               
                                Toast.makeText(context, results.getJSONObject(1).getString("formatted_address"));

                        }else{                                
                                //ajax error, show error code
                                Toast.makeText(aq.getContext(), "Error:" + status.getCode(), Toast.LENGTH_LONG).show();
                        }
                }
        });        
}
吃→可爱长大的 2024-10-20 03:01:05

浪费了几个小时后,我得到了一个最简单的解决方案。

我刚刚重新启动了我的设备,它就开始工作了。

看来,该问题是由于某些操作系统级别的缓存问题造成的。希望它也适用于您..

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..

反话 2024-10-20 03:01:05

我有同样的问题。我使用了以下功能。

笔记:

使用 Activity 的 context,并且不要对以下函数使用 getApplicationContext()

public static Address getLocalityFrmGeoCoder(Context context, Location mLocation) {
        try {
            if(mLocation!=null){
            Geocoder gCoder = new Geocoder(context, Locale.getDefault());
            List<Address> address = gCoder.getFromLocation(mLocation.getLatitude(), mLocation.getLongitude(), 1);
            if (address.size() > 0) {
                return address.get(0);
            }
            }

        } catch (Exception e) {
            Log.d("GEOCODER", "GEOCODER EXCEPTION");
            e.printStackTrace();

        }
    return null;
}

I had the same issue. I used the following function.

Note:

Use context of your Activity and don't use getApplicationContext() to the following function

public static Address getLocalityFrmGeoCoder(Context context, Location mLocation) {
        try {
            if(mLocation!=null){
            Geocoder gCoder = new Geocoder(context, Locale.getDefault());
            List<Address> address = gCoder.getFromLocation(mLocation.getLatitude(), mLocation.getLongitude(), 1);
            if (address.size() > 0) {
                return address.get(0);
            }
            }

        } catch (Exception e) {
            Log.d("GEOCODER", "GEOCODER EXCEPTION");
            e.printStackTrace();

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