Android Google Play 服务:发出位置请求的最佳做法
Android Google Play Service: Best practices to make location request
以下是 LocationRequest API
官方指南 site 中的当前引用
In between these two extremes is a very common use-case, where
applications definitely want to receive updates at a specified
interval, and can receive them faster when available, but still want a
low power impact. These applications should consider
PRIORITY_BALANCED_POWER_ACCURACY combined with a faster
setFastestInterval(long) (such as 1 minute) and a slower
setInterval(long) (such as 60 minutes). They will only be assigned
power blame for the interval set by setInterval(long), but can still
receive locations triggered by other applications at a rate up to
setFastestInterval(long). This style of request is appropriate for
many location aware applications, including background usage. Do be
careful to also throttle setFastestInterval(long) if you perform
heavy-weight work after receiving an update - such as using the
network.
我的顾虑与这些方法有关
LocationRequest setFastestInterval(long millis)
明确设置位置更新的最快间隔,以毫秒为单位。
LocationRequest setInterval(long millis)
设置活动位置更新所需的时间间隔,以毫秒为单位。
让我们说数字...
如果我设置 interval=30s 和 fastest=8s,那么在 t=8、t=16、t=24(8 的倍数)我从其他应用程序获得更新?如果没有 运行 个位置感知应用程序怎么办?
30 多岁能看到新的更新吗?该更新是否算作我的应用程序的功耗?怎么估计的?
那么如果这是正确的,那么这两个参数之间的良好关系是什么才能在不消耗大量电量的情况下获得实时更新?例如 interval=6 x fastest?
我会自己尝试,但我无法重复指南描述的场景,我也无法区分哪些更新是电源问题。
如果您的应用可以持续跟踪位置,则需要定期获取设备的位置。虽然您可以使用 getLastLocation() 获取设备的位置,但更直接的方法是从融合位置提供程序请求定期更新。作为响应,API 会根据当前可用的位置提供程序(例如 WiFi 和 GPS)使用最佳可用位置定期更新您的应用程序。
在请求位置更新之前,您的应用必须连接到位置服务并发出位置请求。位置请求到位后,您可以通过调用 Google API 客户端提供的 requestLocationUpdates()
. Do this in the onConnected() 回调开始定期更新,客户端准备就绪时调用。
尝试阅读 Location Strategies
, the strategies described in this guide apply to the platform location API in android.location. Also, show the for `obtaining user location and defining a Model for the Best Performance'
以下是 LocationRequest API
官方指南 site 中的当前引用In between these two extremes is a very common use-case, where applications definitely want to receive updates at a specified interval, and can receive them faster when available, but still want a low power impact. These applications should consider PRIORITY_BALANCED_POWER_ACCURACY combined with a faster setFastestInterval(long) (such as 1 minute) and a slower setInterval(long) (such as 60 minutes). They will only be assigned power blame for the interval set by setInterval(long), but can still receive locations triggered by other applications at a rate up to setFastestInterval(long). This style of request is appropriate for many location aware applications, including background usage. Do be careful to also throttle setFastestInterval(long) if you perform heavy-weight work after receiving an update - such as using the network.
我的顾虑与这些方法有关
LocationRequest setFastestInterval(long millis)
明确设置位置更新的最快间隔,以毫秒为单位。
LocationRequest setInterval(long millis)
设置活动位置更新所需的时间间隔,以毫秒为单位。
让我们说数字... 如果我设置 interval=30s 和 fastest=8s,那么在 t=8、t=16、t=24(8 的倍数)我从其他应用程序获得更新?如果没有 运行 个位置感知应用程序怎么办? 30 多岁能看到新的更新吗?该更新是否算作我的应用程序的功耗?怎么估计的?
那么如果这是正确的,那么这两个参数之间的良好关系是什么才能在不消耗大量电量的情况下获得实时更新?例如 interval=6 x fastest?
我会自己尝试,但我无法重复指南描述的场景,我也无法区分哪些更新是电源问题。
如果您的应用可以持续跟踪位置,则需要定期获取设备的位置。虽然您可以使用 getLastLocation() 获取设备的位置,但更直接的方法是从融合位置提供程序请求定期更新。作为响应,API 会根据当前可用的位置提供程序(例如 WiFi 和 GPS)使用最佳可用位置定期更新您的应用程序。
在请求位置更新之前,您的应用必须连接到位置服务并发出位置请求。位置请求到位后,您可以通过调用 Google API 客户端提供的 requestLocationUpdates()
. Do this in the onConnected() 回调开始定期更新,客户端准备就绪时调用。
尝试阅读 Location Strategies
, the strategies described in this guide apply to the platform location API in android.location. Also, show the for `obtaining user location and defining a Model for the Best Performance'