Geocoder不适用于某些Android手机 [英] Geocoder doesn't work on some of the Android phones

查看:138
本文介绍了Geocoder不适用于某些Android手机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发Android应用程序,该应用程序允许用户输入地址并将其转换为经纬度以供进一步使用。我使用以下代码来获得lat和长



 地址= geocoder.getFromLocationName( 11381 Zapata的AVE圣地亚哥,1) ; 

if(addresses.size()> 0){
double latitude = addresses.get(0).getLatitude();
double longitude = addresses.get(0).getLongitude();

addGeoFence(经度,纬度);
tlFragmentMap.setLatLong(new LatLng(latitude,longitude));
返回true;
} else {
return false;
}

此地理编码器仅适用于部分手机。任何人都可以告诉我一种让它适用于所有手机的方法。我不想使用任何API。我的编译SDK版本是22,的minSdkVersion是14和targetSdkVersion是22


解决方案

使用地理编码的 isPresent() 方法来确定它是否存在于当前设备中(该服务不在核心框架中呈现)。



更多信息可以在官方文档



作为后备(或可能是唯一的,因为它可以在所有设备上运行)解决方案,可以使用谷歌的 Geocoding rest API


I am working on Android application which allows user to enter the address and converts to latitude and longitude for further use. I am using following code to get lat and long

          addresses = geocoder.getFromLocationName("11381 zapata ave san diego", 1);

        if (addresses.size() > 0) {
            double latitude = addresses.get(0).getLatitude();
            double longitude = addresses.get(0).getLongitude();

            addGeoFence(latitude, longitude);
            tlFragmentMap.setLatLong(new LatLng(latitude, longitude));
            return true;
        } else {
            return false;
        }

This Geocoder works fine on some of the phones only. Can any one suggest me a way to make it work for all the phones. I don't want to use any API. My Compile SDK version is 22, minSdkVErsion is 14 and targetSdkVersion is 22

解决方案

Use Geocoder's isPresent() method to determine whether it is present on current device (this service is not presented in core framework).

More info can be found in the official documentation

As a fallback (or may be the only one, because it is guaranteed to work on all devices) solution one can use google's Geocoding rest API

这篇关于Geocoder不适用于某些Android手机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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