在我正在编写的应用程序中,我必须使用GPS 6.1(供您参考)。 我正在使用以下代码添加地理围栏:
LocationServices.GeofencingApi.addGeofences(mGoogleApiClient, normGeofences, pendingIntent);
并将每个requestId放在共享首选项中,如下所示:
set.add(geofence.getRequestId());
保存集:
sp.edit().putStringSet(ID_KEY, set).commit();
比应用关闭。在某个时间点,用户按下取消地理围栏的通知:
连接到googleApiClient:
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addApi(LocationServices.API)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
mGoogleApiClient.connect();
删除地理围栏:
public void onConnected(Bundle bundle) {
Log.d(TAG, "Connected");
insertGeoIds();
// the method insertgeofences put the request ids in the List geoList
if (mGeoList.size() > 0)
LocationServices.GeofencingApi.removeGeofences(mGoogleApiClient, mGeoList);
}
所以,这不起作用,地理围栏不断被触发。
答案 0 :(得分:0)
PendingResult<Status> pendingResult = LocationServices.GeofencingApi.removeGeofences(mGoogleApiClient, mCurrentGeofenceIds);
pendingResult.setResultCallback(new ResultCallback<Status>() {
@Override
public void onResult(Status status) {
onRemoveGeofencesByRequestIdsResult(status.getStatusCode());
}
});
&#13;