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?
//in the on click
LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER, whatshouldIputhere?, 0, this);
and
public void onLocationChanged(Location location) {
if (location != null) {
double lat = location.getLatitude();
double lng = location.getLongitude();
}
}
I’ve got this working:
It’s simple. It gets the best available provider and gets its last known position.
If you want it only with the GPS, try this.
Hope it helps!
EDITED:
try this:
This code gets the last known location and then do a request for the actual location.