什么时候应该使用 ACCESS_COARSE_LOCATION 权限?

我正在构建一个 Android 应用程序,它可以追踪用户的地理位置,并在地图上绘制他们的路线。

我正在使用谷歌播放服务位置 API,如 给你所述。

直观地说,我的应用程序需要 ACCESS_FINE_LOCATION许可,我把它放在清单中:

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

我还需要 ACCESS_COARSE_LOCATION许可吗? 我需要粗糙位置的用例是什么?

82406 次浏览

Do I also need the ACCESS_COARSE_LOCATION permission?

No.

What's the use case where I need the coarse location?

If you do not ask for ACCESS_FINE_LOCATION, but you need location data, and you are willing for that data to be fuzzy (say, up to around a city block from the user's position). In the case of LocationManager, you can only use the NETWORK_PROVIDER; in the case of the Play Services fused location provider, they should handle this internally.

Once upon a time, long long ago, users were told at install time whether the app wanted coarse or fine location access. Users might accept apps that wanted coarse access but reject apps that wanted fine access.

Since the UI for this has changed, and users would have a fair bit of difficulty determining whether an app wants coarse or fine location permission, I suspect that most developers just ask for fine location permission. That being said, if you know that your app does not need that level of accuracy (e.g., you want the location for a weather forecast), asking for coarse location permission is a nice "tip of the hat" in the direction of privacy and may prove beneficial once again in the future.

UPDATE 2021-11-16: Android 12 changes the UI if you ask for ACCESS_FINE_LOCATION. The user now has the option of downgrading you to only getting ACCESS_COARSE_LOCATION access, by choosing "Approximate" instead of "Precise".

No you don't need to use coarse location.

Coarse location is for network provider's location and fine location is for both GPS provider and network location provider. So fine location covers both and you don't need to use anther one.

In order to receive location updates from NETWORK_PROVIDER or GPS_PROVIDER, you must request the user's permission by declaring either the ACCESS_COARSE_LOCATION or ACCESS_FINE_LOCATION permission, respectively, in your Android manifest file. Without these permissions, your application will fail at runtime when requesting location updates.

If you are using both NETWORK_PROVIDER and GPS_PROVIDER, then you need to request only the ACCESS_FINE_LOCATION permission, because it includes permission for both providers. Permission for ACCESS_COARSE_LOCATION allows access only to NETWORK_PROVIDER.

This is a link for your reference.

Location can be determined by two ways:

Using NETWORK_PROVIDER
Using GPS_PROVIDER
  1. Using NETWORK_PROVIDER

    Android permissions required for using this provider are either ACCESS_COARSE_LOCATION or ACCESS_FINE_LOCATION.

  2. Using GPS_PROVIDER

    Android permissions required for using this provider are only ACCESS_FINE_LOCATION

In simple word ACCESS_FINE_LOCATION gives you better and accurate location and ACCESS_COARSE_LOCATION gives you less accurate location.

ACCESS_FINE_LOCATION includes ACCESS_COARSE_LOCATION. However, there is a catch:

ACCESS_COARSE_LOCATION gives you last-known location which is battery friendly https://developer.android.com/training/location/retrieve-current.html#setup This has a dependency on Google Play Services

However, if you need something like live/ real-time location, use ACCESS_FINE_LOCATION It gives you live/ real-time location. You'll need to use a LocationListener though.