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?