title: How to get country name in android?
body: <p>Hi I am working with android.I had created a GPS app for getting the current location.Now How can I get the country name from the latitude and longitude value ? is it possible ? please help me and thanks :)</p>
  
  <p>here is my code I used</p>
  
  <pre><code> public class AndroidGPSTrackingActivity extends Activity {
  
  Button btnShowLocation;
  
  // GPSTracker class
  GPSTracker gps;
  String countryCode,countryName;
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
  
      btnShowLocation = (Button) findViewById(R.id.btnShowLocation);
  
      // show location button click event
      btnShowLocation.setOnClickListener(new View.OnClickListener() {
  
          @Override
          public void onClick(View arg0) {        
              // create class object
              gps = new GPSTracker(AndroidGPSTrackingActivity.this);
  
              // check if GPS enabled     
              if(gps.canGetLocation()){
  
                  double latitude = gps.getLatitude();
                  double longitude = gps.getLongitude();
                  Log.i("location", " "+latitude+" "+longitude);
                  // \n is for new line
                  try
                  {Geocoder gcd = new Geocoder(getApplicationContext(), Locale.getDefault());
                  List&lt;Address&gt; addresses = gcd.getFromLocation(latitude,longitude, 1);
                  if (addresses.size() &gt; 0) 
                      Toast.makeText(getApplicationContext(), "name "+addresses.get(0).getLocality(),Toast.LENGTH_SHORT).show();
  
                      //System.out.println(addresses.get(0).getLocality());
                  }
  
                       catch (IOException e) {
  
                              e.printStackTrace();
                  }
                  //Toast.makeText(getApplicationContext(), "Your Location is - \nLat: " + latitude + "\nLong: " + longitude+countryName +"  "+countryCode, Toast.LENGTH_LONG).show();    
              }else{
                  // can't get location
                  // GPS or Network is not enabled
                  // Ask user to enable GPS/network in settings
                  gps.showSettingsAlert();
              }
  
          }
      });
  }
  
   }
  </code></pre>