title: how to get gps location android
body: <p>I am trying to have a constant gps listener that will send its location (long and lat coordinates) to a web server every x mins. On a button click it will also send its location to the webserver. I realize that to get the gps signal you type in how often to find a position, but how do I write a program that can get the gps location and send its coordinates every x mins (even in the background when not and by a button press? </p>
  
  <p>//in the on click</p>
  
  <pre><code>LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
  locationManager.requestLocationUpdates(
          LocationManager.GPS_PROVIDER, whatshouldIputhere?, 0, this);
  </code></pre>
  
  <p>and </p>
  
  <pre><code>public void onLocationChanged(Location location) {
      if (location != null) {
          double lat = location.getLatitude();
          double lng = location.getLongitude();
      }
  }
  </code></pre>