I need to find the user position with a timeout, then I wrote a code like this
Start a LocationListener
GPSLocationListener = new LocationListener() { @Override public void onLocationChanged(Location location) { _timerGPSLocation.cancel(); } @Override public void onStatusChanged(String provider, int status, Bundle b) { } @Override public void onProviderEnabled(String s) { } @Override public void onProviderDisabled(String s) { } }; _locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, minTime, minDistance, _GPSLocationListener);
`
Setup a timer for the timeout
_timerGPSLocation = new Timer(); _timerGPSLocation.schedule( new TimerTask() { @Override public void run() { _locationManager.removeUpdates(_GPSLocationListener); } }, (long)(timeout*1000) );
I think that doing this (trying to read coordinates and setup a timer with timeout) for many times can let the GPS contact some satellites and give me the right location. There is a better way for doing this? Calling _locationManager.removeUpdates on the timeout will remove all contacted satellites?
EDIT:
My goal is to read the GPS at regular intervals (5 minutes). I need also to set a timeout while try to get the location using GPS read. if no location is read after the timeout I need to stop the location listener. I've achieved this using the code liste here.
Now my question is if removing the LocationListener because it's go in timeout will cause the loss of the "acknowledgement" between the GPS and the satellite.