How to use a value inside a method outside of that method (location)
<p>I'm am new to android, and I am attempting make a program that would send one's latitude and longitude to a database and store it there. However, I've hit a problem: I can't figure out how to be able to use the lat and lng obtained. The loc.getLatitude() and loc.getLongitude() are inside the method mylocationlistner which does not allow me to use outside of that... What am I supposed to do?????</p>

<pre><code>public class MyLocation2 extends MapActivity {

private MapView myMap;
private MyLocationOverlay myLocOverlay;
private MapController controller;
Location loc;


LocationManager lm;
LocationListener ll;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    initMap();
    initMyLocation();

    // Acquire a reference to the system Location Manager
    LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);

    // Define a listener that responds to location updates
    LocationListener locationListener = new LocationListener() {
        public void onLocationChanged(Location location) {
          // Called when a new location is found by the network location provider.
          **double lat = location.getLatitude();
          double lng = location.getLongitude();**
        } //as u can see, they are inside here

        public void onStatusChanged(String provider, int status, Bundle extras) {}

        public void onProviderEnabled(String provider) {}

        public void onProviderDisabled(String provider) {}
      };

    // Register the listener with the Location Manager to receive location updates


    UpdateLoc(lat, lng);  **&lt;------THIS IS WHERE I WANT TO PLUG THE VALUES IN**
}

/**
 * Initialise the map and adds the zoomcontrols to the LinearLayout.
 */
private void initMap() {
    myMap = (MapView) findViewById(R.id.mymap);

    @SuppressWarnings("deprecation")
    View zoomView = myMap.getZoomControls();
    LinearLayout myzoom = (LinearLayout) findViewById(R.id.myzoom);
    myzoom.addView(zoomView);
    myMap.displayZoomControls(true);


}

/**
 * Initialises the MyLocationOverlay and adds it to the overlays of the map
 */
private void initMyLocation() {
    myLocOverlay = new MyLocationOverlay(this, myMap);
    myLocOverlay.enableMyLocation();
    myMap.getOverlays().add(myLocOverlay);

    controller = myMap.getController();
    myLocOverlay.runOnFirstFix(new Runnable() {
                public void run() {
                    controller.setZoom(17);
                    controller.animateTo(myLocOverlay.getMyLocation());
                }
            });

}





@Override
protected boolean isRouteDisplayed() {
    return false;
}

 @Override
 protected void onResume() {
  // TODO Auto-generated method stub
  super.onResume();
  myLocOverlay.enableMyLocation();   
 }

 @Override
 protected void onPause() {
  // TODO Auto-generated method stub
  super.onPause();
  myLocOverlay.disableMyLocation();   
 } 

 public void UpdateLoc(final double latitude, final double longitude){

        InputStream is = null;


        //the year data to send
        ArrayList&lt;NameValuePair&gt; nameValuePairs = new ArrayList&lt;NameValuePair&gt;();
        nameValuePairs.add(new DoubleNameValuePair("latitudeE6",latitude));
        nameValuePairs.add(new DoubleNameValuePair("longitudeE6",longitude));

        //http post
        try{
                HttpClient httpclient = new DefaultHttpClient();
                HttpPost httppost = new HttpPost("http://bryankim.in/program/UpdateUserLoc.php");
                httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
                HttpResponse response = httpclient.execute(httppost);
                HttpEntity entity = response.getEntity();
                is = entity.getContent();
        }catch(Exception e){
                Log.e("log_tag", "Error in http connection "+e.toString());
        }
        //convert response to string



 }

 //for &lt;String, Double&gt; NameValuePair
 public class DoubleNameValuePair implements NameValuePair {

        String name;

        double value;

        public DoubleNameValuePair(String name, double value) {
            this.name = name;
            this.value = value;
        }

        @Override
        public String getName() {
            return name;
        }

        @Override
        public String getValue() {
            return Double.toString(value);
        }

    }
</code></pre>

<p>}</p>
