GPRC Error with Geocoder on Android

1

Good, someone knows because of a month here when using getFromLocation with Geocoder, it gives an IOException error: GRPC failed.

The code is as follows:

public String getCountryCode(Context context) {
    Geocoder geocoder = new Geocoder(context, Locale.getDefault());
    List<Address> addresses;
    try {
        //Address adr=(Address)geocoder.getFromLocation(latitude, longitude, 1);
        addresses = geocoder.getFromLocation(latitude, longitude, 1);
        //return adr.getCountryCode();
        if (addresses != null && !addresses.isEmpty()) {
            return addresses.get(0).getCountryCode();
        }
        //Address result;
    } catch (IOException e) {
        //do something
        e.printStackTrace();
        //return null;
    }
    return null;
}

Thanks in advance.

    
asked by Lopiv2 12.09.2017 в 10:52
source

1 answer

0

You say that it worked without a problem and now you get the error:

  

IOException error: GRPC failed.

first check that your API is enabled in:

link

Review the documentation , which indicates using the isPresent () to determine if the Geocoder implementation exists, it may be that the device or emulator used does not support it, eg :

public String getCountryCode(Context context) {
    Geocoder geocoder = new Geocoder(context, Locale.getDefault());

     if(geocoder.isPresent()){
        Log.i("GEOCODER", "Geocoder presente!");
     }else
       Log.e("GEOCODER", "Geocoder no soportado"); 
       return null;
     }

    List<Address> addresses;
    try {
        //Address adr=(Address)geocoder.getFromLocation(latitude, longitude, 1);
        addresses = geocoder.getFromLocation(latitude, longitude, 1);
        //return adr.getCountryCode();
        if (addresses != null && !addresses.isEmpty()) {
            return addresses.get(0).getCountryCode();
        }
        //Address result;
    } catch (IOException e) {
        //do something
        e.printStackTrace();
        //return null;
    }
    return null;
}

If it exists, it ensures that the values of latitude and longitude are valid (longitude).

    
answered by 13.09.2017 в 01:51