title: How to get user's GPS coordinates by clicking a button
body: <p>i want to make application like this :</p>
  
  <p>User clicks the button
  The application show the user's coordinates (Latitude and Longitude)</p>
  
  <p>i'm following the steps <a href="http://developer.android.com/guide/topics/location/obtaining-user-location.html#Updates" rel="nofollow">here</a></p>
  
  <pre><code>// Acquire a reference to the system Location Manager
      LocationManager locationManager = (LocationManager) getApplicationContext().getSystemService(Context.LOCATION_SERVICE);
  
      // Define a listener that responds to location updates
      LocationListener locationListener = new LocationListener() {
          @Override
          public void onLocationChanged(Location location) {
            // Called when a new location is found by the network location provider.
            double glat = location.getLatitude();
            double glong = location.getLongitude();
            Toast.makeText(getApplicationContext(), "Your position\n"+glat+"\n"+glong, Toast.LENGTH_LONG).show();
          }
          @Override
          public void onStatusChanged(String provider, int status, Bundle extras) {}
          @Override
          public void onProviderEnabled(String provider) {}
          @Override
          public void onProviderDisabled(String provider) {}
        };
  
      // Register the listener with the Location Manager to receive location updates
      locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);
  </code></pre>
  
  <p>how to implement it to button click event?</p>
  
  <p>if the user clicks the button, the toast appear showing the position :)</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>I implement it using startActivityForResult() but the result is empty or null
  here's my code :</p>
  
  <p>this is the code on the button that i want to click</p>
  
  <pre><code>btn_obj_useKor.setOnClickListener(new View.OnClickListener() {
     @Override
     public void onClick(View arg0) {             
       Intent intent = new Intent(getApplicationContext(), MyLocationListener.class);
       startActivityForResult(intent, 0);
     }
  });
  </code></pre>
  
  <p>and this is my MyLocationListener class :</p>
  
  <pre><code>public class MyLocationListener extends Activity{
  
      Intent intent;
      String output = "";
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          Intent intent = getIntent();
  
          LocationManager locationManager = (LocationManager) getApplicationContext().getSystemService(Context.LOCATION_SERVICE);
  
          LocationListener locationListener = new LocationListener() {
              @Override
              public void onLocationChanged(Location location) {
                  double glat = location.getLatitude();
                  double glong = location.getLongitude();
                  output = glat+","+glong;                
              }
              @Override
              public void onStatusChanged(String provider, int status, Bundle extras) {}
              @Override
              public void onProviderEnabled(String provider) {}
              @Override
              public void onProviderDisabled(String provider) {}
          };
  
          locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);
  
          intent.putExtra("returnedData", output);
          setResult(RESULT_OK, intent);
          finish();
      }
  
  }
  </code></pre>
  
  <p>When i click the button it showing WTF! that means the result is null or empty.</p>
  
  <p>what's the problem and what should i do then?</p>