0

I have the problem that if I try to get an address with the geocoder.getFromLocationName("California",1) function, it founds the address but if I test it on my device (Xiaomi Mi5, Oreo) it returns an empty list.

Thanks in advance!

private void geoLocate(){
    Log.d(TAG, "geoLocate: geolocating");
    String searchString = mSearchText.getText().toString();
    Log.d(TAG, "geoLocate: Searching for " + searchString);
    Geocoder geocoder = new Geocoder(this);
    List<Address> list = new ArrayList<>();

    try{
        if(geocoder.isPresent()){
             list = geocoder.getFromLocationName(searchString,1);
        } else{
            Log.d(TAG, "geoLocate: GEOCODER IS NOT PRESENT");
        }

    }catch (IOException e){
        Log.e(TAG, "geoLocate: IOException " + e.getMessage() );
    }

    if(list.size() > 0 ){
        Address address = list.get(0);
        Log.d(TAG, "geoLocate: found a location: " + address.toString());
    }else{
        Log.d(TAG, "geoLocate: Location not found");
    }

}

2 Answers2

0

Have you given Location permission to your application on your phone? if not .. go to yourapp >> permission >>> locationPermission...

0

It might have been caused by a bug in manufacturer's implementation or a deliberate lack of that feature. As stated here: https://developer.android.com/reference/android/location/Geocoder

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. Use the isPresent() method to determine whether a Geocoder implementation exists.

przan
  • 31
  • 4