protected override async Task InitializeAsync() { await base.InitializeAsync(); if (Location != null) { #region foreground monitoring _foregroundIndoorLocationManager = new EILIndoorLocationManager(); EstimoteForegroundIndoorLocationManagerDelegate foregroundLocationManagerDelegate = new EstimoteForegroundIndoorLocationManagerDelegate(); foregroundLocationManagerDelegate.UpdatedPositionAsync += async(position, accuracy, location) => { EstimoteIndoorLocationAccuracy accuracyEnum = (EstimoteIndoorLocationAccuracy)Enum.Parse(typeof(EstimoteIndoorLocationAccuracy), accuracy.ToString(), true); await StoreDatumAsync(new EstimoteIndoorLocationDatum(DateTimeOffset.UtcNow, position.X, position.Y, position.Orientation, accuracyEnum, location.Name, location.Identifier, location, position)); }; _foregroundIndoorLocationManager.Delegate = foregroundLocationManagerDelegate; #endregion #region background monitoring _backgroundIndoorLocationManager = new EILBackgroundIndoorLocationManager(); EstimoteBackgroundIndoorLocationManagerDelegate backgroundLocationManagerDelegate = new EstimoteBackgroundIndoorLocationManagerDelegate(); backgroundLocationManagerDelegate.UpdatedPositionAsync += async(position, accuracy, location) => { EstimoteIndoorLocationAccuracy accuracyEnum = (EstimoteIndoorLocationAccuracy)Enum.Parse(typeof(EstimoteIndoorLocationAccuracy), accuracy.ToString(), true); await StoreDatumAsync(new EstimoteIndoorLocationDatum(DateTimeOffset.UtcNow, position.X, position.Y, position.Orientation, accuracyEnum, location.Name, location.Identifier, location, position)); }; _backgroundIndoorLocationManager.Delegate = backgroundLocationManagerDelegate; #endregion } }
public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions) { // get your app ID and token on: // https://cloud.estimote.com/#/apps/add/your-own-app ESTConfig.SetupAppIdAndToken("app ID", "app token"); locationManager = new EILIndoorLocationManager(); // C# style delegates, i.e., events & event handlers locationManager.DidUpdatePosition += (sender, e) => { Debug.WriteLine($"DidUpdatePosition: {e.Position.X}, {e.Position.Y}"); }; locationManager.DidFailToUpdatePosition += (sender, e) => { Debug.WriteLine($"DidFailToUpdatePosition: {e.Error}"); }; // For Obj-C style delegates, you'd want to have a class that derives from EILIndoorLocationManagerDelegate, implements the DidUpdatePosition and DidFailToUpdatePosition methods, and do: // locationManager.Delegate = myDelegateObject; // // Or, implement the DidUpdatePosition and DidFailToUpdatePosition methods on any class, and do: // locationManager.WeakDelegate = myDelegateObject; // // The latter is helpful in some cases, because Xamarin Delegates are implemented as classes, not interfaces, and thus are subject to the "single-class inheritance" rule. // // For example, you can't have AppDelegate be both UIApplicationDelegate and EILIndoorLocationManagerDelegate. // But you can implement the EILIndoorLocationManagerDelegate methods in your AppDelegate, and assign it as a WeakDelegate. Debug.WriteLine("Fetching location…"); new EILRequestFetchLocation("my-test-location").SendRequest((location, error) => { if (location != null) { Debug.WriteLine("Fetching location success! Starting position updates"); locationManager.StartPositionUpdatesForLocation(location); } else { Debug.WriteLine($"Can't fetch location: {error}"); } }); return(true); }
public override void DidFailToUpdatePosition(EILIndoorLocationManager locationManager, NSError error) { SensusServiceHelper.Get().Logger.Log("Failed to update indoor location position: " + error, LoggingLevel.Normal, GetType()); }
public override async void DidUpdatePosition(EILIndoorLocationManager locationManager, EILOrientedPoint position, EILPositionAccuracy positionAccuracy, EILLocation location) { await(UpdatedPositionAsync?.Invoke(position, positionAccuracy, location) ?? Task.CompletedTask); }