title: Android get Location in Button click
body: <p>I try to get the location in button click. I wrote <code>LocationListener</code> method and everything working perfect.This is my source</p>
  
  <pre><code>private class MyLocationListener implements LocationListener {
  
      @Override
      public void onLocationChanged(Location loc) {
          editLocation.setText("");
          pb.setVisibility(View.INVISIBLE);
          Toast.makeText(
                  getBaseContext(),
                  "Location changed: Lat: " + loc.getLatitude() + " Lng: "
                      + loc.getLongitude(), Toast.LENGTH_SHORT).show();
          String longitude = "Longitude: " + loc.getLongitude();
          Log.v(TAG, longitude);
          String latitude = "Latitude: " + loc.getLatitude();
          Log.v(TAG, latitude);
  
          /*------- To get city name from coordinates -------- */
          String cityName = null;
          Geocoder gcd = new Geocoder(getBaseContext(), Locale.getDefault());
          List&lt;Address&gt; addresses;
          try {
              addresses = gcd.getFromLocation(loc.getLatitude(),
                      loc.getLongitude(), 1);
              if (addresses.size() &gt; 0) {
                  System.out.println(addresses.get(0).getLocality());
                  cityName = addresses.get(0).getLocality();
              }
          }
          catch (IOException e) {
              e.printStackTrace();
          }
          String s = longitude + "\n" + latitude + "\n\nMy Current City is: "
              + cityName;
          editLocation.setText(s);
      }
  
      @Override
      public void onProviderDisabled(String provider) {}
  
      @Override
      public void onProviderEnabled(String provider) {}
  
      @Override
      public void onStatusChanged(String provider, int status, Bundle extras) {}
  }
  </code></pre>
  
  <p>I can check latitude and longitude with <code>LocationListener</code>, but how i can get current location in button click ?  </p>