je pourrais avoir un simple morceau de code ici pour vous. Lorsque vous démarrez le GPS, vous définissez simplement les limites de temps et de distance. Ne pas oublier également de tuer ceci lorsque vous quittez votre application (dernière méthode ci-dessous)
private static LocationListener gpsLocationListener = null;
/* GPS will not detach and update every 30 minutes if the delta > 25 meters */
private void getGPSLocation(Context context){
gpsLocationListener = new GPSLocationListener();
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1800000, 25, gpsLocationListener);
}
private class GPSLocationListener implements LocationListener{
public void onLocationChanged(Location location){
if(location != null){
final double lat = location.getLatitude();
final double lng = location.getLongitude();
// can do your other implementation here //
}
}
@Override
public void onProviderDisabled(String provider){ }
@Override
public void onProviderEnabled(String provider){ }
@Override
public void onStatusChanged(String provider, int status, Bundle extras){ }
}
private void killGPS(){
if(locationManager != null && gpsLocationListener != null){
locationManager.removeUpdates(gpsLocationListener); }
}
}
Hope this helps
-serkan
vérifier ce lien http://android-developers.blogspot.com/2011/06/deep-dive-into-location.html – Sandeep