LocationRequest setInterval (long millis) 和 LocationRequest setFastestInterval (long millis) 的区别

Difference between LocationRequest setInterval (long millis) and LocationRequest setFastestInterval (long millis)(LocationRequest setInterval (long millis) 和 LocationRequest setFastestInterval (long millis) 的区别)

本文介绍了LocationRequest setInterval (long millis) 和 LocationRequest setFastestInterval (long millis) 的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 android 中每隔 5 分钟编写一次我自己的后台位置更新.我想知道 setInterval 和 setFastestInterval 的区别

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

当我将Interval 设置为 5 分钟并将FastestInterval 设置为 2 分钟时.每 2 分钟调用一次位置更新.

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

我想知道区别.我不明白这个 https:///developer.android.com/reference/com/google/android/gms/location/LocationRequest.html

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

另外:只有当第一次更新的距离超过 20 米且第二次更新时,是否有内置功能来检查位置更新?

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?

谢谢!

推荐答案

基于相关Android 文档:

  • setInterval(long) 意思是 - 设置你想要获取位置的时间间隔.
  • setFastestInterval(long) 意思是 - 如果一个位置可用,您可以更快地获取它(即另一个应用程序正在使用位置服务).
  • 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).

例如,您启动应用程序并通过 setInterval(60*1000) 进行注册,这意味着您将每 60 秒获得一次更新.

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

现在您调用 setFastestInterval(10*1000).如果您是唯一使用定位服务的应用程序,您将继续大约每 60 秒接收一次更新.如果另一个应用正在使用更新率更高的位置服务,您将获得更多位置更新(但不会比每 10 秒更频繁).

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.

这篇关于LocationRequest setInterval (long millis) 和 LocationRequest setFastestInterval (long millis) 的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:LocationRequest setInterval (long millis) 和 LocationRequest setFastestInterval (long millis) 的区别

基础教程推荐