0

I have an application that must collect address from a marker on Google Maps API. I tested this code and it works fine on devices that run Android 6.0 :

Geocoder geocoder = new Geocoder(this, Locale.getDefault());
        try {
            List<Address> addressList1 = geocoder.getFromLocation(currentLatitude,currentLongitude,1);
            Address addressCurrent = addressList1.get(0);
            full_address = addressCurrent.getAddressLine(0); //Detail address
            country = addressCurrent.getCountryName();
            //locality =  addressCurrent.getLocality(); //sub-district
            admin_area = addressCurrent.getAdminArea(); //City
            sub_admin_area = addressCurrent.getSubAdminArea(); //District
            road_name = addressCurrent.getThoroughfare(); // road
            Toast.makeText(this, full_address, Toast.LENGTH_SHORT).show();
        }catch (IOException e){
            Toast.makeText(this, "No Data", Toast.LENGTH_SHORT).show();
            Log.e("error geocoder", e.toString());
        }

But when I try to run on Android 8.1 devices it returns an error log:

E/error geocoder: java.io.IOException: NetCode:-1000,NetRes:{}

I tried to search for it but found no solution. How can I fix this?

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Sơn Tùng
  • 11
  • 6

1 Answers1

0

As Gencoder doc say: Use the isPresent() method to determine whether a Geocoder implementation exists.

so call isPresent() method firstly, and manually check device network status.

If still failed, maybe you need create custom Geocoder implementation, this link is helpful.

navylover
  • 12,383
  • 5
  • 28
  • 41