2

in my project , i use GoogleApiClient and locationRequest to get current location and update it periodically after certain interval , I know that there is difference between setInterval and setFastestInterval and

interval is variable that i change from my app settings and has the values of

so I call this :

        public int interval = 1 * 1000;

        locationRequest.setFastestInterval(interval);
        locationRequest.setInterval(interval);



            switch (interval_index)

    {
        case 0:
            interval = 1 * 1000;
            break;
        case 1:
            interval = 1 * 60 * 1000;
            break;
        case 2:
            interval = 5 * 60 * 1000;
            break;
        case 3:
            interval = 10 * 60 * 1000;
            break;
        case 4:
            interval = 30 * 60 * 1000;
            break;
    }

if i set interval for example to 30 minutes i get updates after 5 minutes for example , it is not constant time but i get updates randomly so why ?

adel omar
  • 79
  • 1
  • 7

1 Answers1

1

There's two ways to trigger the update, Time and Distance, when you set the Interval (is the slowest time constant for the update), FastestInterval (is the minimum time to update) and setSmallestDisplacement is the minimum distance (in meters) for the update.

Even if you still in the same place, the location may change depending on your accuracy and that will trigger the onLocationChange

  • i didn't use setSmallestDisplacement so what i expect is that locationRequest use only my interval in time ? – adel omar Jul 05 '16 at 14:21
  • The default value is 0 meters, so may trigger in any change https://developers.google.com/android/reference/com/google/android/gms/location/LocationRequest – Lucas Queiroz Ribeiro Jul 05 '16 at 14:30
  • i want to disable it like in location manager in android api when set min distance to zero it ignores distance at all and depends only on time what if i make it big number and interval of mill seconds to 3000 for example , does it depends on time only or needs to exceed the big number of distance to request location updates ? – adel omar Jul 05 '16 at 14:35
  • I think you can use a big distance, but, what the point ? the interval is used to pick locations and update the user, if you will use the location only one time in half a hour, is better to remove the update and start listen again in 30 minutes, is a bad practice to leave the GPS listening but not updating (Battery drain) – Lucas Queiroz Ribeiro Jul 05 '16 at 14:46