Geocoder doesn't work on some of the Android phones

落爺英雄遲暮 提交于 2019-12-22 15:01:07

问题


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:


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



来源:https://stackoverflow.com/questions/31146775/geocoder-doesnt-work-on-some-of-the-android-phones

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!