从Android上的GPS提供商处获取*粗略*位置

前端之家收集整理的这篇文章主要介绍了从Android上的GPS提供商处获取*粗略*位置前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我的应用程序只需要非常粗略的位置数据,所以我最初将我的清单权限设置为ACCESS_COARSE_LOCATION,并为NETWORK_PROVIDER设置位置监听器.这给了我所需的粗略位置估算,但只有Google位置服务开启.

我期待如果用户只启用了GPS,我仍然可以得到他们位置的粗略估计.但似乎从GPS_PROVIDER获取任何位置信息的唯一方法是使用ACCESS_FINE_LOCATION权限.

那么,只有启用GPS,应用程序无法接收位置信息,除非它具有ACCESS_FINE_LOCATION权限吗?换句话说,如果应用只有ACCESS_COARSE_LOCATION权限,则GPS_PROVIDER无法发送粗略的位置估算值?

解决方法

So,is it true that with only GPS enabled,an app cannot receive location information unless it has the ACCESS_FINE_LOCATION permission?

一般来说,是的.

引用the documentation for LocationManager

If your application only has the coarse permission then it will not have access to the GPS or passive location providers. Other providers will still return location results,but the update rate will be throttled and the exact location will be obfuscated to a coarse level of accuracy.

In other words,the GPS_PROVIDER can’t send rough location estimates if the app only has ACCESS_COARSE_LOCATION permission?

引用Android 4.2 release notes

Compared to prevIoUs versions of Android,user location results may be less accurate if your app requests the ACCESS_COARSE_LOCATION permission but does not request the ACCESS_FINE_LOCATION permission.
To meet the privacy expectations of users when your app requests permission for coarse location (and not fine location),the system will not provide a user location estimate that’s more accurate than a city block.

但是,我假设这不会取代LocationManager中的“将无法访问GPS”语句.我认为这意味着如果认为NETWORK_PROVIDER数据太准确,可能会被禁止.

猜你在找的Android相关文章