如何仅通过 ACCESS_COARSE_LOCATION 使用 GeofencingApi

How to use GeofencingApi with just ACCESS_COARSE_LOCATION

我正在尝试使用地理围栏,但我不想获得用户的确切位置。所以我正在使用 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