Geocoder doesn't work on some of the Android phones

时间:2015-06-30 19:26:08

标签: android google-maps geocoding rails-geocoder

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

1 个答案:

答案 0 :(得分:2)

使用Geocoder的isPresent()方法确定它是否存在于当前设备上(此服务未在核心框架中显示)。

可以在official documentation

中找到更多信息

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