Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get User Current Location name in Arabic?

I need to get the location name in arabic ,if gps enable for english i am using the following code.

        Geocoder geocoder = new Geocoder(getApplicationContext(), Locale.getDefault());

       // LogCat: Display language = English

        Log.i("Display language = ", "" + mLocale.getDisplayLanguage());

        Log.i("geocoder geocoder = ", "" + geocoder.toString());

      // Geocoder geocoder = new Geocoder(getApplicationContext(), Locale.getDefault());
        try {
            List<Address> listAddresses = geocoder.getFromLocation(latitude, longitude, 1);
            if (null != listAddresses && listAddresses.size() > 0) {
                String _Location = listAddresses.get(0).getAddressLine(0);
               // Log.i("_Location = ", "" + _Location);

                Address address = listAddresses.get(0);

                Log.i("address = ", "" + address);
                result = address.getLocality();

                Log.i("result = ", "" + result);
                // Toast.makeText(getApplicationContext(), "Your Location  NAME is -" + result , Toast.LENGTH_LONG).show();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }

Address[addressLines=[ Abu Dhabi - United Arab Emirates"],feature=3rd Street,admin=Abu Dhabi,sub-admin=null,locality=Abu Dhabi,thoroughfare=3rd Street,postalCode=null,countryCode=AE,countryName=United Arab Emirates,hasLatitude=true,latitude=,hasLongitude=true,longitude=,phone=null,url=null,extras=null]

i need the locality value in arabic based on user selected language in app.

i given Locale mLocale = new Locale("ar","AE"); but it is giving country name comming arabic i need locality value in arabic.

in galaxy s7 data coming correctly based on arabic selection giving arabic data

s6 not comming it is giving english data only if i pass locale arabic also.

like image 615
Venkat Avatar asked Oct 18 '22 08:10

Venkat


1 Answers

In recent reference, Locale has information of language/country code which are suitable in ISO 639-1/ISO 3166-1.

ISO 639-1 is two-letter lowercase language code. Arabic is defined ar in this format.

You can set locale for Arabic like this :

Locale loc = new Locale("ar");

Note:

Android Locale reference: https://developer.android.com/reference/java/util/Locale.html

ISO 639-1 code reference: https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes

hope that its works for you.

like image 152
Nilam Vaddoriya Avatar answered Oct 21 '22 05:10

Nilam Vaddoriya