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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With