问题
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