static AwarenessFence CreateLocationFence() { return(AwarenessFence.Or( LocationFence.Entering(0, 0, 1000), LocationFence.Exiting(0, 0, 1000), LocationFence.In(0, 0, 1000, 100) )); }
private async Task RequestLocationSnapshotAsync() { if (await CrossPermissions.Current.CheckPermissionStatusAsync(Permission.Location) == PermissionStatus.Granted) { // store current location ILocationResult locationResult = await Awareness.SnapshotApi.GetLocationAsync(AwarenessApiClient); global::Android.Locations.Location location = locationResult.Location; DateTimeOffset timestamp = new DateTimeOffset(1970, 1, 1, 0, 0, 0, new TimeSpan()).AddMilliseconds(location.Time); await StoreDatumAsync(new LocationDatum(timestamp, location.HasAccuracy ? location.Accuracy : -1, location.Latitude, location.Longitude)); // replace the previous location fence with one around the current location. additions and removals are handled // in the order specified below. FenceUpdateRequestBuilder locationFenceRequestBuilder = new FenceUpdateRequestBuilder(); UpdateRequestBuilder(null, AWARENESS_EXITING_LOCATION_FENCE_KEY, FenceUpdateAction.Remove, ref locationFenceRequestBuilder); AwarenessFence locationFence = LocationFence.Exiting(location.Latitude, location.Longitude, _locationChangeRadiusMeters); UpdateRequestBuilder(locationFence, AWARENESS_EXITING_LOCATION_FENCE_KEY, FenceUpdateAction.Add, ref locationFenceRequestBuilder); await UpdateFencesAsync(locationFenceRequestBuilder.Build()); } }