title: How do I get a GPS location on a button click?
body: <p>I have some rough code for my project, and I am trying to get the GPS location of the user when a button is pressed and I want the location to be a GeoPoint that I can then pass to a method.</p>
  
  <p>The method is for an Overlay class which draws the Overlay that point. I was using some code from Stack Overflow question <em><a href="https://stackoverflow.com/questions/3428188">How can I obtain the current GPS location?</a></em>. I have the program set up so that the GeoPoint is added to an array and then it is retreived from that array and added to the method. Is there is a better way of doing this or is there any way of using the point without putting it in an array?</p>
  
  <p>This is the button where the Overlay is added and the GeoPoint is gotten from the array:</p>
  
  <pre><code>Button startBtn = (Button) findViewById(R.id.startBtn);
  startBtn.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View arg0) {
          // TODO Auto-generated method stub
          getLocation();
  
          tempOverlay = (MapOverlay) listOfOverlays.get(arrayNumber);
          tempOverlay.addPoint(points.get(pointCount));
          mapView.postInvalidate();
          }
      }
  });
  </code></pre>
  
  <p>This is the getLocation() method which creates the locationManager and requestUpdates.</p>
  
  <pre><code>public void getLocation()
  {
      lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
      locationListener = new MyLocationListener();
      lm.requestLocationUpdates(LocationManager.GPS_PROVIDER,0,0,locationListener);
  
      System.out.println("Get Location Called");
  }
  </code></pre>
  
  <p>This is the <code>onLocationChanged</code> method inside the <code>MyLocationListener</code> class which gets the updates and once I have a location I stop the request for updates.</p>
  
  <pre><code>@Override
  public void onLocationChanged(Location loc)
  {
      if(loc != null)
      {
             Toast.makeText(getBaseContext(),"LocationChanged : Lat: " + loc.getLatitude()+ " Lng: " + loc.getLongitude(),
              Toast.LENGTH_SHORT).show();
      }
  
      p = new GeoPoint((int) (loc.getLatitude() * 1E6),(int) (loc.getLongitude() * 1E6));
  
      points.add(p);
      System.out.println("Point Added to Array");
  
      LBServicesActivity.this.lm.removeUpdates(this);
  
      mc.animateTo(p);
      mc.setZoom(18);
  }
  </code></pre>
  
  <p>How would I pass that GeoPoint to the method in the buttonListener without adding it to an array? </p>