android.location.LocationManager.PASSIVE_PROVIDER 的含义是什么?
我理解 GPS_PROVIDER 的含义(位置来自 GPS 信号)和 NETWORK_PROVIDER (位置由单元格确定塔和无线接入点),但我不明白 PASSIVE_PROVIDER 的含义,尽管 API 中有这样的定义:
特殊位置提供商 接收位置实际上没有 启动位置修复。这 提供者可以用来被动地 当其他人接收位置更新时 应用程序或服务请求它们 没有实际请求 自己定位。该提供商将 返回其他生成的位置 提供商。您可以查询 getProvider() 方法来确定 位置更新的来源。 需要许可 android.permission.ACCESS_FINE_LOCATION, 尽管如果未启用 GPS 该提供者可能只返回粗略的 修复。
为什么人们会使用这个而不是其他提供商之一?为了节省电池寿命?被动提供程序是否仅在其他应用程序明确请求来自真实提供程序的数据时才返回有用的信息,或者从中请求位置总是安全的?
I understand the meaning of GPS_PROVIDER (locations come from GPS signals) and NETWORK_PROVIDER (locations are determined from cell towers and wireless access points), but I don't understand the meaning of PASSIVE_PROVIDER, despite the definition in the API:
A special location provider for
receiving locations without actually
initiating a location fix. This
provider can be used to passively
receive location updates when other
applications or services request them
without actually requesting the
locations yourself. This provider will
return locations generated by other
providers. You can query the
getProvider() method to determine the
origin of the location update.
Requires the permission
android.permission.ACCESS_FINE_LOCATION,
although if the GPS is not enabled
this provider might only return coarse
fixes.
Why would one use this instead of one of the other providers? To save battery life? Does the passive provider only return useful information if some other app explicitly requests data from the real providers, or is it always safe to request locations from this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
该提供商对于与用户位置配合使用但不想浪费电池寿命的服务非常有用,正如您所指出的。
例如,谷歌纬度将您当前的位置发送到网络服务,让您的朋友知道您所在的位置。如果此服务每 5 分钟请求一次 GPS 修复,则设备电池将很快耗尽。如果该服务请求被动位置提供程序,则每次启动 Google 地图并获取修复或某些其他应用程序启动位置提供程序更新时都会发送位置,并且该服务可以对位置数据进行操作,而无需在位置更新上花费额外的电量。
如果您在某个特定时刻需要正确的位置数据,那么使用此提供商将无济于事。对于大多数不在后台服务中运行的事物,此位置提供程序是无用的,因为它仅在其他应用程序触发用户位置更新时才会发送更新。
This provider is useful for services that work with the users location but don't want to waste battery life as you pointed out.
For example Google Latitude sends your current location to a web service to let your friends know where you are. If this service would request a GPS fix every 5 minutes the device battery will be empty very fast. If the service requests a passive location provider a location is send every time Google maps is started and a fix aquired or some other apps initiates a location provider update and the service can act on location data without spending additional power on the location updates.
If you need correct location data at an exact moment using this provider won't help. For most things that are not running in a background service this location provider is useless because it will only send updates if other apps trigger an update of the user location.
要添加到@Janusz,当您收到其他提供商提供的修复程序并且您希望知道此修复程序来自哪个提供商(网络或GPS)时,您可以调用 getProvider() 来查找它。
To add to @Janusz, when you receive a fix due to someone else's provider and you wish to know from what provider is this fix from (NETWORK or GPS), you can call the getProvider() to find this.