反向地理编码在某些android设备中不起作用? [英] Reverse geocoding is not working in some android devices?

查看:159
本文介绍了反向地理编码在某些android设备中不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个地图应用程序,我无法获得这个手机的地址,它的android版本是4.3,就像下面那样 -



但它在我的手机上工作正常,它的版本是4.1.2,如下所示 -





在一些棒棒糖版本中它工作正常。

  final Geocoder gc = new Geocoder(this,Locale.getDefault()); 
尝试{
列表<地址>地址= gc.getFromLocation(lat,lng,1);
StringBuilder sb = new StringBuilder();
if(addresses.size()> 0){
Address address = addresses.get(0);
for(int i = 0; i< address.getMaxAddressLineIndex(); i ++){
if(address.getAddressLine(i).equals(null)){

} else {
sb.append(address.getAddressLine(i))。append(\\\
);
sb.append(address.getLocality())。append(\\\
);
//sb.append(address.getPostalCode()).append(\"\\\
);
//sb.append(address.getCountryName());


// Toast.makeText(RegistrationTest.this,Text Address is+ sb.toString(),Toast.LENGTH_SHORT).show();
text_address = sb.toString();

} catch(Exception e){
//Toast.makeText(RegistrationTest.this,exception+ e,Toast.LENGTH_SHORT).show();
}

对不起,我的英语,感谢您的时间和帮助!

解决方案

Geocoder没有实现由所有制造商。这可能是它无法在特定设备上工作的原因。从 Geocoder 文档:


Geocoder类需要一个未包含在核心android框架中的后端服务。如果平台中没有后端服务,则Geocoder查询方法将返回空列表。


或者可能有请求限额。 p>

您可以使用远程服务,例如 Google地图地理编码API (也是配额)。


I am developing an application on maps, am not able to get address in this mobile, its android version is 4.3, like below --

But it is working fine in my mobile, its version is 4.1.2, like below --

It is working fine in some lollipop versions.

    final Geocoder gc = new Geocoder(this, Locale.getDefault());
    try {
        List<Address> addresses = gc.getFromLocation(lat, lng, 1);
        StringBuilder sb = new StringBuilder();
        if (addresses.size() > 0) {
            Address address = addresses.get(0);
            for (int i = 0; i < address.getMaxAddressLineIndex(); i++) {
                if (address.getAddressLine(i).equals("null")) {

                } else {
                    sb.append(address.getAddressLine(i)).append("\n");
                    sb.append(address.getLocality()).append("\n");
                    //sb.append(address.getPostalCode()).append("\n");
                    //sb.append(address.getCountryName());
                }
            }
           // Toast.makeText(RegistrationTest.this, "Text Address is " + sb.toString(), Toast.LENGTH_SHORT).show();
            text_address = sb.toString();
        }
    } catch (Exception e) {
        //Toast.makeText(RegistrationTest.this, "exception " + e, Toast.LENGTH_SHORT).show();
    }

Sorry for my english, and thank you for your time and help!

Please help me, am stuck here!

解决方案

Geocoder is not implemented by all manufacturers. It's may be a reason why it doesn't work on a particular device. From the Geocoder documentation :

The Geocoder class requires a backend service that is not included in the core android framework. The Geocoder query methods will return an empty list if there no backend service in the platform

Or perhaps there is a request quota.

Instead you can use a remote service like Google Maps geocoding API (quotas too).

这篇关于反向地理编码在某些android设备中不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆