title: change interval of the LocationRequest depending on distance between current and some location
body: <p>I want to save battery by changing the interval of updates using the Fused Location API. As far from some location, bigger should be the interval.</p>
  
  <pre><code>public class service extends Service implements GooglePlayServicesClient.ConnectionCallbacks,GooglePlayServicesClient.OnConnectionFailedListener,LocationListener {
      private LocationRequest locationrequest;
      private LocationClient locationclient;
  
  
  
      @Override
      public void onCreate() {
  
          int resp = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
          if (resp == ConnectionResult.SUCCESS) {
              locationclient = new LocationClient(this, this, this);
              locationclient.connect();
          } else {
              Toast.makeText(this, "Google Play Service Error " + resp, Toast.LENGTH_LONG).show();
  
          }
  
      }
  
  
  
      @Override
      public void onDestroy() {
          super.onDestroy();
          if(locationclient!=null)
              locationclient.disconnect();
      }
  
      @Override
      public IBinder onBind(Intent intent) {
          return null;
      }
  
      @Override
      public void onConnected(Bundle connectionHint) {
          Log.i(TAG, "onConnected");
          if (locationclient != null &amp;&amp; locationclient.isConnected()) {
              locationrequest = LocationRequest.create();
              locationrequest.setInterval(5000);
              locationrequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
              locationclient.requestLocationUpdates(locationrequest, this);
  
          }
      }
  
      @Override
      public void onDisconnected() {
          Log.i(TAG, "onDisconnected");
  
  
      }
  
      @Override
      public void onConnectionFailed(ConnectionResult result) {
          Log.i(TAG, "onConnectionFailed");
  
  
      }
  
      @Override
      public void onLocationChanged(Location location) {
          if(location!=null){
              double Lat=-34.922611;
              double Lng = 138.596161;
              Location Loc = new Location("");
              Loc.setLatitude(Lat);
              Loc.setLongitude(Lng);
              Float dist=location.distanceTo(Loc);
              String distance = Float.toString(dist);
              if (dist&gt;100){
                  Log.i("distance",distance);
                  locationclient.removeLocationUpdates(this);
                  locationrequest.setInterval(30000);
                  locationrequest.setPriority(LocationRequest.PRIORITY_LOW_POWER);
                  locationclient.requestLocationUpdates(locationrequest, this);
  
              }
  
              Log.i(TAG, "Location Request :" + location.getLatitude() + "," + location.getLongitude());
  
  
          }
  
      }
  }
  </code></pre>
  
  <p>Unfortunately this is not working.. somebody knows why? or is there a better way to do that?
  thanks </p>
  
  <p>EDIT 1:
  What I am getting as output is a locationrequest that behaves in the same way  before the change. If I call locationrequest.getInterval , the new interval will be show but the locationrequest will give me updates with the first interval.</p>