Exemple #1
0
        public IObservable <CompassReading> WhenReadingTaken()
        {
            this.readOb = this.readOb ?? Observable.Create <CompassReading>(ob =>
            {
                var handler = new EventHandler <CLHeadingUpdatedEventArgs>((sender, args) =>
                {
                    var accuracy = this.FromNative(args.NewHeading.HeadingAccuracy);
                    var read     = new CompassReading(accuracy, args.NewHeading.MagneticHeading, args.NewHeading.TrueHeading);
                    ob.OnNext(read);
                });
                var lm = new CLLocationManager
                {
                    DesiredAccuracy = CLLocation.AccuracyBest,
                    HeadingFilter   = 1
                };
                lm.UpdatedHeading += handler;
                lm.StartUpdatingHeading();

                return(() =>
                {
                    lm.StopUpdatingHeading();
                    lm.UpdatedHeading -= handler;
                });
            })
                          .Publish()
                          .RefCount();

            return(this.readOb);
        }
Exemple #2
0
        public IObservable <CompassReading> WhenReadingTaken()
        {
            this.readOb = this.readOb ?? Observable.Create <CompassReading>(ob =>
            {
                var handler = new TypedEventHandler <Compass, CompassReadingChangedEventArgs>((sender, args) =>
                {
                    var accuracy = this.FromNative(args.Reading.HeadingAccuracy);
                    var read     = new CompassReading(accuracy, args.Reading.HeadingMagneticNorth, args.Reading.HeadingTrueNorth ?? 0);
                    ob.OnNext(read);
                });
                this.compass.ReadingChanged += handler;

                return(() => this.compass.ReadingChanged -= handler);
            })
                          .Publish()
                          .RefCount();

            return(this.readOb);
        }