android - 如何仅通过 ACCESS_COARSE_LOCATION 使用 GeofencingApi

标签 android android-geofence google-location-services

我正在尝试使用地理围栏,但我不想获取用户的确切位置。所以我正在使用 ACCESS_COARSE_LOCATION。如果我使用大型地理围栏点圆,我认为 ACCESS_COARSE_LOCATION 将正常工作。可能工作不完美,但它可以大致了解用户位置。

在这样的文档代码

        try {
        LocationServices.GeofencingApi.addGeofences(
                mGoogleApiClient,
                // The GeofenceRequest object.
                getGeofencingRequest(),
                // A pending intent that that is reused when calling removeGeofences(). This
                // pending intent is used to generate an intent when a matched geofence
                // transition is observed.
                getGeofencePendingIntent()
        ).setResultCallback(this); // Result processed in onResult().
    } catch (SecurityException securityException) {
        // Catch exception generated if the app does not use ACCESS_FINE_LOCATION permission.
        logSecurityException(securityException);
    }

但它给出了错误,因为 GeofencingApi.addGeofences 需要 FINE_LOCATION 权限。如何将地理围栏与 COARSA_LOCATION 结合使用

最佳答案

你不能。 您需要 ACCESS_FINE_LOCATION 才能使用地理围栏 API。

引用文档:

The first step in requesting geofence monitoring is to request the necessary permission. To use geofencing, your app must request ACCESS_FINE_LOCATION.

https://developer.android.com/training/location/geofencing.html#RequestGeofences

关于android - 如何仅通过 ACCESS_COARSE_LOCATION 使用 GeofencingApi,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43574951/

相关文章:

javascript - jQuery 在页面底部滚动时加载更多内容

java - Eclipse Android 两个按钮

Android:地理围栏的最小和最大半径是多少

android - LocationClient 连接和地理围栏

java - Android 地理围栏不触发 IntentService

Android Geofence 在进入/退出时触发,没有错误,但没有 GEOFENCE TRANSITION 标志

适用于多种语言的 Android 一个值文件夹

java - ListView 中的图像从行跳转到行

android - 如何使用 Work Manager 处理来自 FusedLocationProviderClient 的位置更新?

javascript - 位置 Java 脚本在部署后停止工作