Difference between LocationRequest setInterval (long millis) and LocationRequest setFastestInterval (long millis)

TheDevMan picture TheDevMan · Sep 30, 2014 · Viewed 38.6k times · Source

I am writing my own background location updates for interval of every 5 minutes in android. I would like to know the difference between setInterval and setFastestInterval

When I setInterval to 5 mins and setFastestInterval to 2 mins. The location update is called every 2 mins.

I would like to know the difference. I couldn't understand what exactly is written in the developer page for this https://developer.android.com/reference/com/google/android/gms/location/LocationRequest.html

Also: Is there an inbuilt function to check the location updates only if the distances of the first update are more than 20meters with the second update?

Thanks!

Answer

Ohad Zadok picture Ohad Zadok · Oct 16, 2014

Based on the relevant Android documentation:

  • setInterval(long) means - set the interval in which you want to get locations.
  • setFastestInterval(long) means - if a location is available sooner you can get it (i.e. another app is using the location services).

For example, you start your application and register it via setInterval(60*1000), that means that you'll get updates every 60 seconds.

Now you call setFastestInterval(10*1000). If you are the only app which use the location services you will continue to receive updates approximately every 60 seconds. If another app is using the location services with a higher rate of updates, you will get more location updates (but no more frequently that every 10 seconds).

I believe that it has a good impact on battery life consumed by your app, you define the maximum amount of time that you can wait while saying that if an update is available, you want it. The battery consumption will be credited to the app which requested the more frequent updates and not yours.