Reputation: 875
How to get the iso3 country code.when i store the server but it is not store 100% of the database? I am using these code.Please help me Thanks and Advance...
geocoder = new Geocoder(this);
locationManager = (LocationManager)getSystemService(LOCATION_SERVICE);
Criteria criteria = new Criteria();
bestProvider =locationManager.getBestProvider(criteria,false);
location = locationManager.getLastKnownLocation(bestProvider);
if(location!=null)
{
lat=location.getLatitude();
lng=location.getLongitude();
}
else
{
location = new Location("");
location.setLatitude((double)38.0000000000);
location.setLongitude((double)-97.0000000000);
lat =location.getLatitude();
lng=location.getLongitude();
}
Log.e("","Latitude and Longitude"+"Latitude="+lat+"Longitude="+lng);
try
{
addresses=geocoder.getFromLocation(lat,lng, 1);
}
catch (IOException e)
{
e.printStackTrace();
}
if (addresses != null && addresses.size() > 0)
{
Address address = addresses.get(0);
Log.e("Address=",""+address);
locale = address.getCountryCode();
Log.e("Locale",""+locale);
Toast.makeText(SongsList.this, "LocaleName"+locale,Toast.LENGTH_LONG).show();
}
Upvotes: 2
Views: 1591
Reputation: 340
Here is a good working solution.
String countryCodeISO2 = address.getCountryCode();
String CountryCodeISO3 = new Locale("", countryCodeISO2).getISO3Country();
Upvotes: 1