0

I'm triying to get the actually user country with Geocoder . The problem is that sometimes it returns countries' names in English and another times in Spanish. I'm using the same physical device in the same location.

How to define the countries' names Geocoder returns?

I'm using this fuction:

  private static String getPais(double LATITUDE, double LONGITUDE,Context context) {
        String strAdd = "";
        String pais = "";
        Geocoder geocoder = new Geocoder(context, Locale.getDefault());
        try {
            List<Address> addresses = geocoder.getFromLocation(LATITUDE, LONGITUDE, 1);
            if (addresses != null) {
                Address returnedAddress = addresses.get(0);
                StringBuilder strReturnedAddress = new StringBuilder("");

                for (int i = 0; i <= returnedAddress.getMaxAddressLineIndex(); i++) {
                    strReturnedAddress.append(returnedAddress.getAddressLine(i)).append("\n");
                }
                strAdd = strReturnedAddress.toString();
                //    provincia = returnedAddress.getAddressLine(2);
                pais = addresses.get(0).getCountryName();
                Log.w("My Current ion address", strReturnedAddress.toString());
            } else {
                Log.w("My Current tion address", "No Address returned!");
            }
        } catch (Exception e) {
            e.printStackTrace();
            Log.w("My Current loon address", "Canont get Address!");
        }
        //return strAdd;
        return pais;
   }
double-beep
  • 5,031
  • 17
  • 33
  • 41
  • Hi agani... I have a solution, probe this: ``` Geocoder geocoder = new Geocoder(context, Locale.forLanguageTag("EN")); ``` When you declare geocoder (in tag use the language you want it) – happyteknologic Nov 01 '19 at 13:58
  • 1
    Please add a new answer with the solution you found and accept it. – double-beep Nov 03 '19 at 11:26

0 Answers0