如何使用GeofencingApi只使用ACCESS_COARSE_LOCATION

时间:2017-04-23 18:33:01

标签: 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

中使用地理围栏

1 个答案:

答案 0 :(得分:2)

你做不到。 您需要ACCESS_FINE_LOCATION才能使用Geofencing API。

引用文档:

  

请求地理围栏监控的第一步是请求必要的权限。要使用地理围栏,您的应用必须请求ACCESS_FINE_LOCATION。

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