public override GeofenceCircularRegion Get(string id) { GeofenceCircularRegion region = null; if (!string.IsNullOrEmpty(NSUserDefaults.StandardUserDefaults.StringForKey(GetFieldKey(id, IdGeofenceRegionKey)))) { double lat = NSUserDefaults.StandardUserDefaults.DoubleForKey(GetFieldKey(id, LatitudeGeofenceRegionKey)); double lon = NSUserDefaults.StandardUserDefaults.DoubleForKey(GetFieldKey(id, LongitudeGeofenceRegionKey)); bool notifyOnEntry = NSUserDefaults.StandardUserDefaults.BoolForKey(GetFieldKey(id, NotifyOnEntryGeofenceRegionKey)); bool notifyOnExit = NSUserDefaults.StandardUserDefaults.BoolForKey(GetFieldKey(id, NotifyOnExitGeofenceRegionKey)); bool notifyOnStay = NSUserDefaults.StandardUserDefaults.BoolForKey(GetFieldKey(id, NotifyOnStayGeofenceRegionKey)); double radius = NSUserDefaults.StandardUserDefaults.DoubleForKey(GetFieldKey(id, RadiusGeofenceRegionKey)); string notificationEntryMessage = NSUserDefaults.StandardUserDefaults.StringForKey(GetFieldKey(id, NotificationEntryMessageGeofenceRegionKey)); string notificationExitMessage = NSUserDefaults.StandardUserDefaults.StringForKey(GetFieldKey(id, NotificationExitMessageGeofenceRegionKey)); string notificationStayMessage = NSUserDefaults.StandardUserDefaults.StringForKey(GetFieldKey(id, NotificationStayMessageGeofenceRegionKey)); bool showNotification = NSUserDefaults.StandardUserDefaults.BoolForKey(GetFieldKey(id, ShowNotificationGeofenceRegionKey)); bool persistent = NSUserDefaults.StandardUserDefaults.BoolForKey(GetFieldKey(id, PersistentGeofenceRegionKey)); bool showEntryNotification = NSUserDefaults.StandardUserDefaults.BoolForKey(GetFieldKey(id, ShowEntryNotificationGeofenceRegionKey)); bool showExitNotification = NSUserDefaults.StandardUserDefaults.BoolForKey(GetFieldKey(id, ShowExitNotificationGeofenceRegionKey)); bool showStayNotification = NSUserDefaults.StandardUserDefaults.BoolForKey(GetFieldKey(id, ShowStayNotificationGeofenceRegionKey)); int stayedInThresholdDuration = (int)NSUserDefaults.StandardUserDefaults.IntForKey(GetFieldKey(id, StayedInThresholdDurationGeofenceRegionKey)); region = new GeofenceCircularRegion(id, lat, lon, radius, notifyOnEntry, notifyOnExit, notifyOnStay, showNotification, persistent, showEntryNotification, showExitNotification, showStayNotification) { NotificationEntryMessage = notificationEntryMessage, NotificationStayMessage = notificationStayMessage, NotificationExitMessage = notificationExitMessage, StayedInThresholdDuration = TimeSpan.FromMilliseconds(stayedInThresholdDuration) }; } return(region); }
void AddRegion(GeofenceCircularRegion region) { CLRegion cRegion = null; if (UIDevice.CurrentDevice.CheckSystemVersion(7, 0)) { cRegion = new CLCircularRegion(new CLLocationCoordinate2D(region.Latitude, region.Longitude), (region.Radius > locationManager.MaximumRegionMonitoringDistance) ? locationManager.MaximumRegionMonitoringDistance : region.Radius, region.Id); } else { cRegion = new CLRegion(new CLLocationCoordinate2D(region.Latitude, region.Longitude), (region.Radius > locationManager.MaximumRegionMonitoringDistance) ? locationManager.MaximumRegionMonitoringDistance : region.Radius, region.Id); } cRegion.NotifyOnEntry = region.NotifyOnEntry || region.NotifyOnStay; cRegion.NotifyOnExit = region.NotifyOnExit; locationManager.StartMonitoring(cRegion); // Request state for this region, putting request behind a timer per thread: http://stackoverflow.com/questions/24543814/diddeterminestate-not-always-called Task.Run(async() => { await Task.Delay(TimeSpan.FromSeconds(2)); locationManager.RequestState(cRegion); }); }
/// <summary> /// Save a geofence /// </summary> /// <param name="region">The GeofenceCircularRegion with the values you want to save in SharedPreferemces</param> public override void Save(GeofenceCircularRegion region) { if (!region.Persistent) { return; } string id = region.Id; // Get a SharedPreferences editor instance. Among other things, SharedPreferences ensures that updates are atomic and non-concurrent ISharedPreferencesEditor prefs = mPrefs.Edit(); // Write the geofence values to SharedPreferences prefs.PutFloat(GetFieldKey(id, LatitudeGeofenceRegionKey), (float)region.Latitude); prefs.PutFloat(GetFieldKey(id, LongitudeGeofenceRegionKey), (float)region.Longitude); prefs.PutFloat(GetFieldKey(id, RadiusGeofenceRegionKey), (float)region.Radius); prefs.PutBoolean(GetFieldKey(id, NotifyOnEntryGeofenceRegionKey), region.NotifyOnEntry); prefs.PutBoolean(GetFieldKey(id, NotifyOnExitGeofenceRegionKey), region.NotifyOnExit); prefs.PutBoolean(GetFieldKey(id, NotifyOnStayGeofenceRegionKey), region.NotifyOnStay); prefs.PutString(GetFieldKey(id, NotificationEntryMessageGeofenceRegionKey), region.NotificationEntryMessage); prefs.PutString(GetFieldKey(id, NotificationExitMessageGeofenceRegionKey), region.NotificationExitMessage); prefs.PutString(GetFieldKey(id, NotificationStayMessageGeofenceRegionKey), region.NotificationStayMessage); prefs.PutBoolean(GetFieldKey(id, ShowNotificationGeofenceRegionKey), region.ShowNotification); prefs.PutBoolean(GetFieldKey(id, PersistentGeofenceRegionKey), region.Persistent); prefs.PutBoolean(GetFieldKey(id, ShowEntryNotificationGeofenceRegionKey), region.ShowEntryNotification); prefs.PutBoolean(GetFieldKey(id, ShowExitNotificationGeofenceRegionKey), region.ShowExitNotification); prefs.PutBoolean(GetFieldKey(id, ShowStayNotificationGeofenceRegionKey), region.ShowStayNotification); prefs.PutInt(GetFieldKey(id, StayedInThresholdDurationGeofenceRegionKey), (int)region.StayedInThresholdDuration.TotalMilliseconds); // Commit the changes prefs.Commit(); }
/// <summary> /// Starts monitoring region /// </summary> /// <param name="region"></param> public void StartMonitoring(GeofenceCircularRegion region) { if (AvailableForMonitoring()) { if (!mRegions.ContainsKey(region.Id)) { mRegions.Add(region.Id, region); } else { mRegions[region.Id] = region; } GeofenceStore.SharedInstance.Save(region); if (Regions.Count > 20 && locationManager.MonitoredRegions.Count == 20) { RecalculateRegions(); } else { AddRegion(region); } locationManager.StartMonitoringSignificantLocationChanges(); } }
public void AddRegion(GeofenceCircularRegion region) { if (string.IsNullOrEmpty(region.Id)) { return; } RemoveRegion(region.Id); var position = new BasicGeoposition(); position.Latitude = region.Latitude; position.Longitude = region.Longitude; var geocircle = new Geocircle(position, region.Radius); Windows.Devices.Geolocation.Geofencing.MonitoredGeofenceStates mask = 0; if (region.NotifyOnEntry) { mask |= Windows.Devices.Geolocation.Geofencing.MonitoredGeofenceStates.Entered; } if (region.NotifyOnExit) { mask |= Windows.Devices.Geolocation.Geofencing.MonitoredGeofenceStates.Exited; } var geofence = new Windows.Devices.Geolocation.Geofencing.Geofence(region.Id, geocircle, mask, false, new TimeSpan(0, 0, CrossGeofence.StayedInDuration / 1000), DateTime.Now, TimeSpan.MaxValue); Windows.Devices.Geolocation.Geofencing.GeofenceMonitor.Current.Geofences.Add(geofence); GeofenceStore.SharedInstance.Save(region); }
public AboutViewModel() { Title = "About"; OpenWebCommand = new Command(() => Device.OpenUri(new Uri("https://xamarin.com/platform"))); GeofenceCircularRegion region = new GeofenceCircularRegion("Geo1", 10, 10, 1000); CrossGeofence.Current.StartMonitoring(region); }
public override void Save(GeofenceCircularRegion region) { string id = region.Id; Container.Values[GetFieldKey(id, IdGeofenceRegionKey)] = region.Id; Container.Values[GetFieldKey(id, LatitudeGeofenceRegionKey)] = region.Latitude; Container.Values[GetFieldKey(id, LongitudeGeofenceRegionKey)] = region.Longitude; Container.Values[GetFieldKey(id, NotifyOnEntryGeofenceRegionKey)] = region.NotifyOnEntry; Container.Values[GetFieldKey(id, NotifyOnExitGeofenceRegionKey)] = region.NotifyOnExit; Container.Values[GetFieldKey(id, RadiusGeofenceRegionKey)] = region.Radius; }
/// <summary> /// Adds the region. /// </summary> /// <param name="region">Region to add.</param> private void AddRegion(GeofenceCircularRegion region) { CLRegion addingRegion; addingRegion = UIDevice.CurrentDevice.CheckSystemVersion(7, 0) ? new CLCircularRegion(new CLLocationCoordinate2D(region.Latitude, region.Longitude), (region.Radius > this.locationManager.MaximumRegionMonitoringDistance) ? this.locationManager.MaximumRegionMonitoringDistance : region.Radius, region.Id) : new CLRegion(new CLLocationCoordinate2D(region.Latitude, region.Longitude), (region.Radius > this.locationManager.MaximumRegionMonitoringDistance) ? this.locationManager.MaximumRegionMonitoringDistance : region.Radius, region.Id); addingRegion.NotifyOnEntry = region.NotifyOnEntry || region.NotifyOnStay; addingRegion.NotifyOnExit = region.NotifyOnExit; this.locationManager.StartMonitoring(addingRegion); this.locationManager.RequestState(addingRegion); }
/// <summary> /// Starts the monitoring. /// </summary> /// <param name="region">Region that should be monitored.</param> public void StartMonitoring(GeofenceCircularRegion region) { /*if (IsMonitoring && mGoogleApiClient.IsConnected) * { * Android.Gms.Location.LocationServices.GeofencingApi.RemoveGeofences(mGoogleApiClient, GeofenceTransitionPendingIntent).SetResultCallback(this); * }*/ if (!this.modeRegions.ContainsKey(region.Id)) { this.modeRegions.Add(region.Id, region); } this.RequestMonitoringStart(); }
/// <summary> /// Starts monitoring specified region /// </summary> /// <param name="region"></param> public void StartMonitoring(GeofenceCircularRegion region) { lock (Lock) { if (IsMonitoring) { mGeofencingClient.RemoveGeofences(GeofenceTransitionPendingIntent).AddOnCompleteListener(this); } if (!mRegions.ContainsKey(region.Id)) { mRegions.Add(region.Id, region); } } RequestMonitoringStart(); }
public override void Save(GeofenceCircularRegion region) { string id = region.Id; if (string.IsNullOrEmpty(id) || !region.Persistent) { return; } NSUserDefaults.StandardUserDefaults.SetString(region.Id, GetFieldKey(id, IdGeofenceRegionKey)); NSUserDefaults.StandardUserDefaults.SetDouble(region.Latitude, GetFieldKey(id, LatitudeGeofenceRegionKey)); NSUserDefaults.StandardUserDefaults.SetDouble(region.Longitude, GetFieldKey(id, LongitudeGeofenceRegionKey)); NSUserDefaults.StandardUserDefaults.SetBool(region.NotifyOnEntry, GetFieldKey(id, NotifyOnEntryGeofenceRegionKey)); NSUserDefaults.StandardUserDefaults.SetBool(region.NotifyOnExit, GetFieldKey(id, NotifyOnExitGeofenceRegionKey)); NSUserDefaults.StandardUserDefaults.SetBool(region.NotifyOnStay, GetFieldKey(id, NotifyOnStayGeofenceRegionKey)); NSUserDefaults.StandardUserDefaults.SetDouble(region.Radius, GetFieldKey(id, RadiusGeofenceRegionKey)); NSUserDefaults.StandardUserDefaults.SetBool(region.ShowNotification, GetFieldKey(id, ShowNotificationGeofenceRegionKey)); NSUserDefaults.StandardUserDefaults.SetBool(region.Persistent, GetFieldKey(id, PersistentGeofenceRegionKey)); NSUserDefaults.StandardUserDefaults.SetBool(region.ShowEntryNotification, GetFieldKey(id, ShowEntryNotificationGeofenceRegionKey)); NSUserDefaults.StandardUserDefaults.SetBool(region.ShowExitNotification, GetFieldKey(id, ShowExitNotificationGeofenceRegionKey)); NSUserDefaults.StandardUserDefaults.SetBool(region.ShowStayNotification, GetFieldKey(id, ShowStayNotificationGeofenceRegionKey)); NSUserDefaults.StandardUserDefaults.SetInt((int)region.StayedInThresholdDuration.TotalMilliseconds, GetFieldKey(id, StayedInThresholdDurationGeofenceRegionKey)); if (!string.IsNullOrEmpty(region.NotificationEntryMessage)) { NSUserDefaults.StandardUserDefaults.SetString(region.NotificationEntryMessage, GetFieldKey(id, NotificationEntryMessageGeofenceRegionKey)); } if (!string.IsNullOrEmpty(region.NotificationExitMessage)) { NSUserDefaults.StandardUserDefaults.SetString(region.NotificationExitMessage, GetFieldKey(id, NotificationExitMessageGeofenceRegionKey)); } if (!string.IsNullOrEmpty(region.NotificationStayMessage)) { NSUserDefaults.StandardUserDefaults.SetString(region.NotificationStayMessage, GetFieldKey(id, NotificationStayMessageGeofenceRegionKey)); } geofenceIds.Add(id); NSUserDefaults.StandardUserDefaults.SetString(string.Join(IdSeparator, geofenceIds.ToArray <string>()), GeofenceIdsKey); NSUserDefaults.StandardUserDefaults.Synchronize(); }
void AddRegion(GeofenceCircularRegion region) { CLRegion cRegion = null; if (UIDevice.CurrentDevice.CheckSystemVersion(7, 0)) { cRegion = new CLCircularRegion(new CLLocationCoordinate2D(region.Latitude, region.Longitude), (region.Radius > locationManager.MaximumRegionMonitoringDistance) ? locationManager.MaximumRegionMonitoringDistance : region.Radius, region.Id); } else { cRegion = new CLRegion(new CLLocationCoordinate2D(region.Latitude, region.Longitude), (region.Radius > locationManager.MaximumRegionMonitoringDistance) ? locationManager.MaximumRegionMonitoringDistance : region.Radius, region.Id); } cRegion.NotifyOnEntry = region.NotifyOnEntry || region.NotifyOnStay; cRegion.NotifyOnExit = region.NotifyOnExit; locationManager.StartMonitoring(cRegion); locationManager.RequestState(cRegion); }
public override GeofenceCircularRegion Get(string id) { GeofenceCircularRegion region = null; if (Container.Values.ContainsKey(GetFieldKey(id, IdGeofenceRegionKey)) && Container.Values.ContainsKey(GetFieldKey(id, LatitudeGeofenceRegionKey)) && Container.Values.ContainsKey(GetFieldKey(id, LongitudeGeofenceRegionKey)) && Container.Values.ContainsKey(GetFieldKey(id, NotifyOnEntryGeofenceRegionKey)) && Container.Values.ContainsKey(GetFieldKey(id, NotifyOnExitGeofenceRegionKey)) && Container.Values.ContainsKey(GetFieldKey(id, RadiusGeofenceRegionKey))) { region = new GeofenceCircularRegion() { Id = Container.Values[GetFieldKey(id, IdGeofenceRegionKey)].ToString(), Latitude = (double)Container.Values[GetFieldKey(id, LatitudeGeofenceRegionKey)], Longitude = (double)Container.Values[GetFieldKey(id, LongitudeGeofenceRegionKey)], Radius = (double)Container.Values[GetFieldKey(id, RadiusGeofenceRegionKey)], NotifyOnEntry = (bool)Container.Values[GetFieldKey(id, NotifyOnEntryGeofenceRegionKey)], NotifyOnExit = (bool)Container.Values[GetFieldKey(id, NotifyOnExitGeofenceRegionKey)], }; } return(region); }
/// <summary> /// Save a geofence /// </summary> /// <param name="region">The GeofenceCircularRegion with the values you want to save in SharedPreferemces</param> public override void Save(GeofenceCircularRegion region) { if (!region.Persistent) { return; } string id = region.Id; // Get a SharedPreferences editor instance. Among other things, SharedPreferences ensures that updates are atomic and non-concurrent ISharedPreferencesEditor prefs = this.modePrefs.Edit(); // Write the geofence values to SharedPreferences prefs.PutFloat(this.GetFieldKey(id, BaseGeofenceStore.LatitudeGeofenceRegionKey), (float)region.Latitude); prefs.PutFloat(this.GetFieldKey(id, BaseGeofenceStore.LongitudeGeofenceRegionKey), (float)region.Longitude); prefs.PutFloat(this.GetFieldKey(id, BaseGeofenceStore.RadiusGeofenceRegionKey), (float)region.Radius); prefs.PutBoolean(this.GetFieldKey(id, BaseGeofenceStore.NotifyOnEntryGeofenceRegionKey), region.NotifyOnEntry); prefs.PutBoolean(this.GetFieldKey(id, BaseGeofenceStore.NotifyOnExitGeofenceRegionKey), region.NotifyOnExit); prefs.PutBoolean(this.GetFieldKey(id, BaseGeofenceStore.NotifyOnStayGeofenceRegionKey), region.NotifyOnStay); prefs.PutString(this.GetFieldKey(id, BaseGeofenceStore.NotificationEntryMessageGeofenceRegionKey), region.NotificationEntryMessage); prefs.PutString(this.GetFieldKey(id, BaseGeofenceStore.NotificationExitMessageGeofenceRegionKey), region.NotificationExitMessage); prefs.PutString(this.GetFieldKey(id, BaseGeofenceStore.NotificationStayMessageGeofenceRegionKey), region.NotificationStayMessage); prefs.PutBoolean(this.GetFieldKey(id, BaseGeofenceStore.ShowNotificationGeofenceRegionKey), region.ShowNotification); prefs.PutBoolean(this.GetFieldKey(id, BaseGeofenceStore.PersistentGeofenceRegionKey), region.Persistent); prefs.PutInt(this.GetFieldKey(id, BaseGeofenceStore.StayedInThresholdDurationGeofenceRegionKey), (int)region.StayedInThresholdDuration.TotalMilliseconds); // Commit the changes prefs.Commit(); }
/// <summary> /// Starts the monitoring. /// </summary> /// <param name="region">Region that should be monitored.</param> public void StartMonitoring(GeofenceCircularRegion region) { /*if (IsMonitoring && mGoogleApiClient.IsConnected) { Android.Gms.Location.LocationServices.GeofencingApi.RemoveGeofences(mGoogleApiClient, GeofenceTransitionPendingIntent).SetResultCallback(this); }*/ if (!this.modeRegions.ContainsKey(region.Id)) { this.modeRegions.Add(region.Id, region); } this.RequestMonitoringStart(); }
/// <summary> /// Starts monitoring region /// </summary> /// <param name="region">Region to monitor</param> public void StartMonitoring(GeofenceCircularRegion region) { if (this.AvailableForMonitoring()) { if (!this.regions.ContainsKey(region.Id)) { this.regions.Add(region.Id, region); } else { this.regions[region.Id] = region; } GeofenceStore.SharedInstance.Save(region); if (this.Regions.Count > 20 && this.locationManager.MonitoredRegions.Count == 20) { this.RecalculateRegions(); } else { this.AddRegion(region); } this.locationManager.StartMonitoringSignificantLocationChanges(); } }
/// <summary> /// Save geofence region in store /// </summary> /// <param name="region">New region.</param> public override void Save(GeofenceCircularRegion region) { string id = region.Id; if (string.IsNullOrEmpty(id) || !region.Persistent) { return; } NSUserDefaults.StandardUserDefaults.SetString(region.Id, this.GetFieldKey(id, BaseGeofenceStore.IdGeofenceRegionKey)); NSUserDefaults.StandardUserDefaults.SetDouble(region.Latitude, this.GetFieldKey(id, BaseGeofenceStore.LatitudeGeofenceRegionKey)); NSUserDefaults.StandardUserDefaults.SetDouble(region.Longitude, this.GetFieldKey(id, BaseGeofenceStore.LongitudeGeofenceRegionKey)); NSUserDefaults.StandardUserDefaults.SetBool(region.NotifyOnEntry, this.GetFieldKey(id, BaseGeofenceStore.NotifyOnEntryGeofenceRegionKey)); NSUserDefaults.StandardUserDefaults.SetBool(region.NotifyOnExit, this.GetFieldKey(id, BaseGeofenceStore.NotifyOnExitGeofenceRegionKey)); NSUserDefaults.StandardUserDefaults.SetBool(region.NotifyOnStay, this.GetFieldKey(id, BaseGeofenceStore.NotifyOnStayGeofenceRegionKey)); NSUserDefaults.StandardUserDefaults.SetDouble(region.Radius, this.GetFieldKey(id, BaseGeofenceStore.RadiusGeofenceRegionKey)); NSUserDefaults.StandardUserDefaults.SetBool(region.ShowNotification, this.GetFieldKey(id, BaseGeofenceStore.ShowNotificationGeofenceRegionKey)); NSUserDefaults.StandardUserDefaults.SetBool(region.Persistent, this.GetFieldKey(id, BaseGeofenceStore.PersistentGeofenceRegionKey)); NSUserDefaults.StandardUserDefaults.SetInt((int)region.StayedInThresholdDuration.TotalMilliseconds, this.GetFieldKey(id, BaseGeofenceStore.StayedInThresholdDurationGeofenceRegionKey)); if (!string.IsNullOrEmpty(region.NotificationEntryMessage)) { NSUserDefaults.StandardUserDefaults.SetString(region.NotificationEntryMessage, this.GetFieldKey(id, BaseGeofenceStore.NotificationEntryMessageGeofenceRegionKey)); } if (!string.IsNullOrEmpty(region.NotificationExitMessage)) { NSUserDefaults.StandardUserDefaults.SetString(region.NotificationExitMessage, this.GetFieldKey(id, BaseGeofenceStore.NotificationExitMessageGeofenceRegionKey)); } if (!string.IsNullOrEmpty(region.NotificationStayMessage)) { NSUserDefaults.StandardUserDefaults.SetString(region.NotificationStayMessage, this.GetFieldKey(id, BaseGeofenceStore.NotificationStayMessageGeofenceRegionKey)); } this.geofenceIds.Add(id); NSUserDefaults.StandardUserDefaults.SetString(string.Join(IdSeparator, this.geofenceIds.ToArray<string>()), GeofenceIdsKey); NSUserDefaults.StandardUserDefaults.Synchronize(); }
/// <summary> /// Gets an specific geofence from store /// </summary> /// <param name="id">Region id.</param> /// <returns>Region of id.</returns> public override GeofenceCircularRegion Get(string id) { GeofenceCircularRegion region = null; if (!string.IsNullOrEmpty(NSUserDefaults.StandardUserDefaults.StringForKey(this.GetFieldKey(id, BaseGeofenceStore.IdGeofenceRegionKey)))) { double lat = NSUserDefaults.StandardUserDefaults.DoubleForKey(GetFieldKey(id, LatitudeGeofenceRegionKey)); double lon = NSUserDefaults.StandardUserDefaults.DoubleForKey(GetFieldKey(id, LongitudeGeofenceRegionKey)); bool notifyOnEntry = NSUserDefaults.StandardUserDefaults.BoolForKey(GetFieldKey(id, NotifyOnEntryGeofenceRegionKey)); bool notifyOnExit = NSUserDefaults.StandardUserDefaults.BoolForKey(GetFieldKey(id, NotifyOnExitGeofenceRegionKey)); bool notifyOnStay = NSUserDefaults.StandardUserDefaults.BoolForKey(GetFieldKey(id, NotifyOnStayGeofenceRegionKey)); double radius = NSUserDefaults.StandardUserDefaults.DoubleForKey(GetFieldKey(id, RadiusGeofenceRegionKey)); string notificationEntryMessage = NSUserDefaults.StandardUserDefaults.StringForKey(GetFieldKey(id, NotificationEntryMessageGeofenceRegionKey)); string notificationExitMessage = NSUserDefaults.StandardUserDefaults.StringForKey(GetFieldKey(id, NotificationExitMessageGeofenceRegionKey)); string notificationStayMessage = NSUserDefaults.StandardUserDefaults.StringForKey(GetFieldKey(id, NotificationStayMessageGeofenceRegionKey)); bool showNotification = NSUserDefaults.StandardUserDefaults.BoolForKey(GetFieldKey(id, ShowNotificationGeofenceRegionKey)); bool persistent = NSUserDefaults.StandardUserDefaults.BoolForKey(GetFieldKey(id, PersistentGeofenceRegionKey)); int stayedInThresholdDuration = (int)NSUserDefaults.StandardUserDefaults.IntForKey(GetFieldKey(id, StayedInThresholdDurationGeofenceRegionKey)); region = new GeofenceCircularRegion(id, lat, lon, radius, notifyOnEntry, notifyOnExit, notifyOnStay, showNotification, persistent) { NotificationEntryMessage = notificationEntryMessage, NotificationStayMessage = notificationStayMessage, NotificationExitMessage = notificationExitMessage, StayedInThresholdDuration = TimeSpan.FromMilliseconds(stayedInThresholdDuration) }; } return region; }