Inheritance: ICompass
Esempio n. 1
0
        //private MapLayer pinLayer;
        public SimpleAR()
        {
            this.InitializeComponent();
            poiLocations = new List<Geopoint>();
            //var accessStatus = await Geolocator.RequestAccessAsync();
            poiLocations.Add(new Windows.Devices.Geolocation.Geopoint(
                new Windows.Devices.Geolocation.BasicGeoposition()
                {
                    Latitude = 47.6166726675232592,
                    Longitude = -122.34717558119712
                }));
            poiLocations.Add(new Windows.Devices.Geolocation.Geopoint(
                new Windows.Devices.Geolocation.BasicGeoposition()
                {
                    Latitude = 47.616743,
                    Longitude = -122.347397
                }));
            poiLocations.Add(new Windows.Devices.Geolocation.Geopoint(
                new Windows.Devices.Geolocation.BasicGeoposition()
                {
                    Latitude = 47.616529,
                    Longitude = -122.347014
                }));
            poiLocations.Add(new Windows.Devices.Geolocation.Geopoint(
                new Windows.Devices.Geolocation.BasicGeoposition()
                {
                    Latitude = 47.616647,
                    Longitude = -122.347207
                }));

            compass = Compass.GetDefault();
                     
        }
        public MainPage()
        {
            InitializeComponent();

            // this.NavigationCacheMode = NavigationCacheMode.Required;
            //DataEntry.saveAll();
            //DataEntry.loadAll();

            this.accelSensor = Accelerometer.GetDefault();
            if (this.accelSensor != null) this.accelSensor.ReadingChanged += new TypedEventHandler<Accelerometer, AccelerometerReadingChangedEventArgs>(myAccelHandler);

            this.compSensor = Compass.GetDefault();
            if (this.compSensor != null) this.compSensor.ReadingChanged += new TypedEventHandler<Compass, CompassReadingChangedEventArgs>(myCompassHandler);

            this.gyroSensor = Gyrometer.GetDefault();
            if (this.gyroSensor != null) this.gyroSensor.ReadingChanged += new TypedEventHandler<Gyrometer, GyrometerReadingChangedEventArgs>(myGyroHandler);

            this.incliSensor = Inclinometer.GetDefault();
            if (this.incliSensor != null) this.incliSensor.ReadingChanged += new TypedEventHandler<Inclinometer, InclinometerReadingChangedEventArgs>(myIncliHandler);

            this.lightSensor = LightSensor.GetDefault();
            if (this.lightSensor != null) this.lightSensor.ReadingChanged += new TypedEventHandler<LightSensor, LightSensorReadingChangedEventArgs>(myLightHandler);

            accelX = accelY = accelZ = comp = gyroX = gyroY = gyroZ = incliYaw = incliPitch = incliRoll = light = 0;

            // Sample code to localize the ApplicationBar
            //BuildLocalizedApplicationBar();
        }
Esempio n. 3
0
        public void getHeading(string options)
        {
            compass = Windows.Devices.Sensors.Compass.GetDefault();
            if (compass == null)
            {
                DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, "{code:" + Not_Supported + "}"));
            }
            else
            {
                var reading = compass.GetCurrentReading();

                var magneticheading = reading.HeadingMagneticNorth;
                var trueheading     = reading.HeadingTrueNorth;
                var headingaccuracy = magneticheading - trueheading;

                string result = String.Format("\"magneticHeading\":{0},\"headingAccuracy\":{1},\"trueHeading\":{2}",
                                              magneticheading.ToString(),
                                              headingaccuracy.ToString(),
                                              trueheading.ToString());

                result = "{" + result + "}";

                PluginResult Result = new PluginResult(PluginResult.Status.OK, result);
                DispatchCommandResult(Result);
            }
        }
Esempio n. 4
0
 void compass_ReadingChanged(Compass sender, CompassReadingChangedEventArgs args)
 {
     Deployment.Current.Dispatcher.BeginInvoke(() =>
         {
             compassReading = args.Reading;
             ShowData();
         });
 }
Esempio n. 5
0
 protected override void OnNavigatedTo(NavigationEventArgs e)
 {
     c = Compass.GetDefault();
     if (c != null)
     {
         c.ReadingChanged += c_ReadingChanged;
         Data.Visibility = Visibility.Visible;
     }
     else NoSensorMessage.Visibility = Visibility.Visible;
 }
      // Sample code for building a localized ApplicationBar
      //private void BuildLocalizedApplicationBar()
      //{
      //    // Set the page's ApplicationBar to a new instance of ApplicationBar.
      //    ApplicationBar = new ApplicationBar();

      //    // Create a new button and set the text value to the localized string from AppResources.
      //    ApplicationBarIconButton appBarButton = new ApplicationBarIconButton(new Uri("/Assets/AppBar/appbar.add.rest.png", UriKind.Relative));
      //    appBarButton.Text = AppResources.AppBarButtonText;
      //    ApplicationBar.Buttons.Add(appBarButton);

      //    // Create a new menu item with the localized string from AppResources.
      //    ApplicationBarMenuItem appBarMenuItem = new ApplicationBarMenuItem(AppResources.AppBarMenuItemText);
      //    ApplicationBar.MenuItems.Add(appBarMenuItem);
      //}

      private async void Start()
      {
         if (!timer.IsEnabled)
         {
            string runningMessage = "Reading: ";

            accelSensor = Accelerometer.GetDefault();
            if (accelSensor != null)
            {
               accelSensor.ReportInterval = 66;
               runningMessage += "Accelerometer ";
            }

            // while not shown in the chapter, get the current location so that 
            // true heading is more accurate.
            Geolocator locator = new Geolocator();
            await locator.GetGeopositionAsync();

            compassSensor = Compass.GetDefault();
            if (compassSensor != null)
            {
               compassSensor.ReportInterval = 66;
               runningMessage += "Compass ";
            }

            try
            {
               gyroSensor = Gyrometer.GetDefault();
            }
            catch (FileNotFoundException) { }

            if (gyroSensor != null)
            {
               gyroSensor.ReportInterval = 66;
               runningMessage += "Gyroscope ";
            }

            inclineSensor = Inclinometer.GetDefault();
            if (inclineSensor != null)
            {
               inclineSensor.ReportInterval = 66;
               runningMessage += "Inclinometer ";
            }

            orientationSensor = OrientationSensor.GetDefault();
            if (orientationSensor != null)
            {
               orientationSensor.ReportInterval = 66;
               runningMessage += "Orientation ";
            }

            timer.Start();
            messageBlock.Text = runningMessage;
         }
      }
 async void c_ReadingChanged(Compass sender, CompassReadingChangedEventArgs args)
 {
     await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
     {
         MagneticNorth.Text = args.Reading.HeadingMagneticNorth.ToString();
         if (args.Reading.HeadingTrueNorth != null)
         {
             TrueNorth.Text = args.Reading.HeadingTrueNorth.ToString();
         }
     });
 }
Esempio n. 8
0
 private static Sensor GetSensor()
 {
     try
     {
         return(Sensor.GetDefault());
     }
     catch
     {
         return(null);
     }
 }
Esempio n. 9
0
        void OnReadingChanged(Sensor sender, CompassReadingChangedEventArgs args)
        {
            var handler = changed;

            if (handler != null)
            {
                var value = ConvertToHeadingNorth(args.Reading);
                var e     = new CompassEventArgs(value);
                handler.Invoke(this, e);
            }
        }
Esempio n. 10
0
 async void _compass_ReadingChanged(Compass sender, CompassReadingChangedEventArgs args)
 {
     var res = args.Reading;
     
     double val = res.HeadingTrueNorth ?? res.HeadingMagneticNorth;
     await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal,
         () =>
         {
             rotatTransform.Angle = -val;
             Display(val);
         });
 }
 async protected override void OnNavigatedTo(NavigationEventArgs e)
 {
     c = Compass.GetDefault();
     if (c != null)
     {
         c.ReadingChanged += c_ReadingChanged;
     }
     else
     {
         MessageDialog dialog = new MessageDialog("没有找到罗盘!");
         await dialog.ShowAsync();
     }
 }
Esempio n. 12
0
 private void Button_Click_1(object sender, RoutedEventArgs e)
 {
     compass = Compass.GetDefault();
     if (compass == null)
     {
         MessageBox.Show("不支持罗盘传感器");
         return;
     }
     compass.ReportInterval = 1000;
     compass.ReadingChanged += compass_ReadingChanged;
     compassReading = compass.GetCurrentReading();
     ShowData();
 }
        /// <summary>
        /// このページがフレームに表示されるときに呼び出されます。
        /// </summary>
        /// <param name="e">このページにどのように到達したかを説明するイベント データ。Parameter 
        /// プロパティは、通常、ページを構成するために使用します。</param>
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            accelerometer = Accelerometer.GetDefault();
            if ( accelerometer!= null ) {
                accelerometer.ReadingChanged += accelerometer_ReadingChanged;
            }

            inclinometer = Inclinometer.GetDefault();
            if ( inclinometer != null ) {
                inclinometer.ReadingChanged += inclinometer_ReadingChanged;
            }

            compass = Compass.GetDefault();
            if ( compass != null ) {
                compass.ReadingChanged += compass_ReadingChanged;
            }
        }
Esempio n. 14
0
        public Scenario1()
        {
            this.InitializeComponent();

            _compass = Compass.GetDefault();
            if (_compass != null)
            {
                // Select a report interval that is both suitable for the purposes of the app and supported by the sensor.
                // This value will be used later to activate the sensor.
                uint minReportInterval = _compass.MinimumReportInterval;
                _desiredReportInterval = minReportInterval > 16 ? minReportInterval : 16;
            }
            else
            {
                rootPage.NotifyUser("No compass found", NotifyType.ErrorMessage);
            }
        }
Esempio n. 15
0
         void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            _compass = Compass.GetDefault();
            if (_compass == null)
            {
                HelpShow.Show("亲,您的手机不支持指南针!");
                return;
            }
            uint v = _compass.MinimumReportInterval;
            uint Interval = 20;
       
            _compass.ReportInterval = (Interval <= v) ? v : Interval;
            _compass.ReadingChanged += _compass_ReadingChanged;
            rotatTransform = new RotateTransform();
            ge.RenderTransform = rotatTransform;

        }
        /// <summary>
        /// Initializes a new instance of the DeviceMotionImplementation class.
        /// </summary>
        public DeviceMotionImplementation()
        {
            accelerometer = Accelerometer.GetDefault();
            gyrometer = Gyrometer.GetDefault();
            compass = Compass.GetDefault();

#if WINDOWS_PHONE_APP
            magnetometer = Magnetometer.GetDefault();
#endif
            sensorStatus = new Dictionary<MotionSensorType, bool>()
            {
				{ MotionSensorType.Accelerometer, false},
				{ MotionSensorType.Gyroscope, false},
				{ MotionSensorType.Magnetometer, false},
                { MotionSensorType.Compass, false}

			};
        }
Esempio n. 17
0
 public Log(MainWindow window, bool isBehavior = false)
 {
     this.window = window;
     this.isBehavior = isBehavior;
     this.statusAnalyzer = new StatusAnalyze(window);
     logDir = Directory.GetCurrentDirectory() + "\\logs\\" + Config.userName+ Config.startTime.ToString("_MM_dd_HH_mm_ss");
     if (!Directory.Exists(logDir))
     {
         Directory.CreateDirectory(logDir);
     }
     logList = new List<LogRecord>();
     this.accelerometer = Accelerometer.GetDefault();
     this.inclinometer = Inclinometer.GetDefault();
     //this.inclinometer.ReadingChanged += onInclinometerReadingChanged;
     this.gyrometer = Gyrometer.GetDefault();
     this.orientationSensor = OrientationSensor.GetDefault();
     this.compass = Compass.GetDefault();
     this.lightsensor = LightSensor.GetDefault();
 }
Esempio n. 18
0
        internal static void PlatformStart(SensorSpeed sensorSpeed)
        {
            sensor = DefaultCompass;
            var interval = NormalInterval;

            switch (sensorSpeed)
            {
            case SensorSpeed.Fastest:
                interval = FastestInterval;
                break;

            case SensorSpeed.Game:
                interval = GameInterval;
                break;
            }

            sensor.ReportInterval = sensor.MinimumReportInterval >= interval ? sensor.MinimumReportInterval : interval;

            sensor.ReadingChanged += CompassReportedInterval;
        }
Esempio n. 19
0
        public MainPage()
        {
            InitializeComponent();
            _locator = new Geolocator();
            Loaded += OnControlLoaded;

            _lightSensor = LightSensor.GetDefault();
            if (_lightSensor != null)
            {
                //For now we get a base reading to use to compare later
                _baseReading = _lightSensor.GetCurrentReading();
                //Register for the reading change
                _lightSensor.ReadingChanged += OnLightReadingChanged;
            }

            _accelerometerSensor = Accelerometer.GetDefault();
            if (_accelerometerSensor != null)
            {
                _accelerometerSensor.Shaken += OnShaken;
            }
            _compassSensor = Compass.GetDefault();
            if (_compassSensor != null)
            {
                _compassSensor.ReadingChanged += OnCompassReadingChanged;
            }
            _gyroSensor = Gyrometer.GetDefault();
            if (_gyroSensor != null)
            {
                _gyroSensor.ReadingChanged += OnGyroReadingChanged;
            }
            _inclineSensor = Inclinometer.GetDefault();
            if (_inclineSensor != null)
            {
                _inclineSensor.ReadingChanged += OnInclineReadingChanged;
            }
            _orientationSensor = OrientationSensor.GetDefault();
            if (_orientationSensor != null)
            {
                _orientationSensor.ReadingChanged += OnOrientationReadingChanged;
            }
        }
        public Scenario2_Polling()
        {
            this.InitializeComponent();

            _compass = Compass.GetDefault();
            if (_compass != null)
            {
                // Select a report interval that is both suitable for the purposes of the app and supported by the sensor.
                // This value will be used later to activate the sensor.
                uint minReportInterval = _compass.MinimumReportInterval;
                _desiredReportInterval = minReportInterval > 16 ? minReportInterval : 16;

                // Set up a DispatchTimer
                _dispatcherTimer = new DispatcherTimer();
                _dispatcherTimer.Tick += DisplayCurrentReading;
                _dispatcherTimer.Interval = new TimeSpan(0, 0, 0, 0, (int)_desiredReportInterval);
            }
            else
            {
                rootPage.NotifyUser("No compass found", NotifyType.ErrorMessage);
            }
        }
 // Constructor
 public MainPage()
 {
     InitializeComponent();
     _fLayer = MyMap.Layers["FLayer"] as FeaturesLayer;
     _eLayer = MyMap.Layers["ELayer"] as ElementsLayer;
     _layer = MyMap.Layers["CLayer"] as CloudLayer;
     _layer.LocalStorage = new OfflineStorage("CloudMap");
     MyMap.ViewBoundsChanged += MyMap_ViewBoundsChanged;
     _watcher = new GeoCoordinateWatcher(GeoPositionAccuracy.High);
     _watcher.MovementThreshold = 20;
     _watcher.PositionChanged += _watcher_PositionChanged;
     _watcher.StatusChanged += _watcher_StatusChanged;
     _compass = Compass.GetDefault();
     if (_compass != null)
     {
         _compass.ReadingChanged += _compass_ReadingChanged;
         _compass.ReportInterval = 100;
     }
     MyMap.Tap += MyMap_Tap;
     MyMap.DoubleTap += MyMap_DoubleTap;
     MyMap.Hold += MyMap_Hold;
 }
Esempio n. 22
0
 public void Rotate()
 {
     _compass = Compass.GetDefault();
     if (_compass != null)
     {
         _dispatcherTimer = new DispatcherTimer();
         _dispatcherTimer.Tick += DisplayCompass;
         _dispatcherTimer.Interval = new TimeSpan(0, 0, 0, 0, 1);
     }
 }
Esempio n. 23
0
        void Sensor_ReadingChanged(Windows.Devices.Sensors.Compass sender, CompassReadingChangedEventArgs args)
        {
            var reading = args.Reading;

            OnChanged(reading.HeadingTrueNorth ?? reading.HeadingMagneticNorth);
        }
 void _compass_ReadingChanged(Compass sender, CompassReadingChangedEventArgs args)
 {
     Dispatcher.BeginInvoke(() =>
         {
             if (_compassFeature != null)
             {
                 CompassMarkerStyle style = _compassFeature.Style as CompassMarkerStyle;
                 style.Rotation = (args.Reading.HeadingTrueNorth.HasValue ? args.Reading.HeadingTrueNorth.Value : 0);
             }
         });
 }
Esempio n. 25
0
        private void compass_ReadingChanged(Compass sender, CompassReadingChangedEventArgs args)
        {
            double angle;
            if (args.Reading.HeadingTrueNorth.HasValue)
            {
                angle = args.Reading.HeadingTrueNorth.Value;
            }
            else
                angle = args.Reading.HeadingMagneticNorth;

            angle = Math.Round(angle, 0);

            dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                // UpdateNorthElementAngle(MapCtrl.Heading);
                UpdateUserLocationElementAngle(angle - MapCtrl.Heading);
                if (compassMode)
                {
                    //.Heading = angle;
                    SetView(userLastLocation, null, angle, null, MapAnimationKind.Linear);
                    //MapCtrl.TrySetViewAsync(userLastLocation, null, angle, null, MapAnimationKind.Linear);
                    //MapCtrl.Heading = angle;
                }
            });
        }
 void CompassReadingChanged(Compass sender, CompassReadingChangedEventArgs args)
 {
     if (args.Reading.HeadingTrueNorth!=null &&SensorValueChanged!=null)
         SensorValueChanged(this, new SensorValueChangedEventArgs { ValueType = MotionSensorValueType.Single, SensorType = MotionSensorType.Compass, Value = new MotionValue() { Value = args.Reading.HeadingTrueNorth} });
 }
        // the values in the sensorArgs are currently not used by the FormulaEditorViewModel,
        // because the FormulaEvaluator uses the Get-Functions to get the current readings
        void _compass_ReadingChanged(Compass sender, CompassReadingChangedEventArgs args)
        {
            try
            {
                CompassReading reading = args.Reading;

                if (reading != null)
                {
                    SensorEventArgs sensorArgs = new SensorEventArgs(reading.HeadingMagneticNorth);

                    if (SensorReadingChanged != null)
                    {
                        SensorReadingChanged(sender, sensorArgs);
                    }
                }
            }
            catch (Exception)
            {
                _compassEnabled = false;
            }

            _compassChecked = true;
        }
Esempio n. 28
0
        /// <summary>
        /// MainPage constructor        
        /// </summary>
        public MainPage()
        {
            this.InitializeComponent();
            _inputProcessor = new SIUC311.Manipulations.InputProcessor(ReportPopupGrid, null);

            // This is a static public property that will allow downstream pages to get 
            // a handle to the MainPage instance in order to call methods that are in this class.
            Current = this;

            // Setup
            SetWindowsUser();
            SetDNSDomain();

            RefreshQueue();
            InitHeadings();
            InitRadioButtons();

            if (haveInternetAccess = CheckForInternet())
            {
                //NotifyUser("Internet.", NotifyType.ReportMessage);
            }
            else
            {
                //NotifyUser("No internet.", NotifyType.ReportMessage);
            }

            appSettings = ApplicationData.Current.LocalSettings.Values;
            _cd = Window.Current.CoreWindow.Dispatcher;

            _geolocatorForTracker = new Geolocator(); // May not need all three. Just synchronize access to one.
            _geolocatorForRequest = new Geolocator();
            _geolocatorForMap = new Geolocator();

            _compass = Compass.GetDefault(); // Get the default compass object

            _inclinometer = Inclinometer.GetDefault(); // Get the default inlinometer object

            _locationIcon10m = new LocationIcon10m();
            _locationIcon100m = new LocationIcon100m();
            _locationIcon2000m = new LocationIcon2000m();

            // Assign an event handler for the compass reading-changed event
            if (_compass != null)
            {
                // Establish the report interval for all scenarios
                uint minReportInterval = _compass.MinimumReportInterval;
                uint reportInterval = minReportInterval > 16 ? minReportInterval : 16;
                _compass.ReportInterval = reportInterval;
                _compass.ReadingChanged += new TypedEventHandler<Compass, CompassReadingChangedEventArgs>(CompassReadingChanged);
            }
            else
            {
                DirectionTextblock.Text = "No compass";
            }

            // Assign an event handler for the inclinometer reading-changed event
            if (_inclinometer != null)
            {
                // Establish the report interval for all scenarios
                uint minReportInterval = _inclinometer.MinimumReportInterval;
                uint reportInterval = minReportInterval > 16 ? minReportInterval : 16;
                _inclinometer.ReportInterval = reportInterval;

                // Establish the event handler
                _inclinometer.ReadingChanged += new TypedEventHandler<Inclinometer, InclinometerReadingChangedEventArgs>(InclinometerReadingChanged);
            }
            else
            {
                DirectionTextblock.Text = "No inclinometer";
            }

            Application.Current.Suspending += (sender, args) => OnSuspending();
            Application.Current.Resuming += (sender, o) => OnResuming();

            Window.Current.VisibilityChanged += Current_VisibilityChanged;

            TitleGrid.Background = new SolidColorBrush(Color.FromArgb(255, 102, 0, 0));
            Map.MapType = MapType.Aerial;
        }
 async void MainPage_ReadingChanged( Compass sender, CompassReadingChangedEventArgs args )
 {
     await Dispatcher.RunAsync( CoreDispatcherPriority.Normal, () =>
     {
         var n = args.Reading.HeadingTrueNorth;
         TextCompass.Text = string.Format( @"Compass:{0}, North:{1}", args.Reading.HeadingMagneticNorth,
             n != null ? n.ToString() : @"Flse" );
     } );
 }
        /// <summary>
        /// このページがフレームに表示されるときに呼び出されます。
        /// </summary>
        /// <param name="e">このページにどのように到達したかを説明するイベント データ。Parameter 
        /// プロパティは、通常、ページを構成するために使用します。</param>
        async protected override void OnNavigatedTo( NavigationEventArgs e )
        {
            // 光センサー
            lightSensor = LightSensor.GetDefault();
            if ( lightSensor != null ) {
                lightSensor.ReadingChanged += MainPage_ReadingChanged;
            }
            else {
                TextLight.Text = @"光センサーはありません";
            }

            //加速度センサー
            accelerometer = Accelerometer.GetDefault();
            if ( accelerometer != null ) {
                accelerometer.ReadingChanged += MainPage_ReadingChanged;
                accelerometer.Shaken += MainPage_Shaken;
            }
            else {
                TextAccelerometer.Text = @"加速度センサーはありません";
            }

            // ジャイロメーター
            gyrometer = Gyrometer.GetDefault();
            if ( gyrometer != null ) {
                gyrometer.ReadingChanged += MainPage_ReadingChanged;
            }
            else {
                TextGyrometer.Text = @"ジャイロメーターはありません";
            }

            // 傾斜センサー
            inclinometer = Inclinometer.GetDefault();
            if ( inclinometer != null ) {
                inclinometer.ReadingChanged += MainPage_ReadingChanged;
            }
            else {
                TextInclinometer.Text = @"傾斜センサーはありません";
            }

            // 方位センサー
            orientationSensor = OrientationSensor.GetDefault();
            if ( orientationSensor != null ) {
                orientationSensor.ReadingChanged += MainPage_ReadingChanged;
            }
            else {
                TextOrientation.Text = @"方位センサーはありません";
            }

            // 簡易方位センサー
            simpleOrientationSensor = SimpleOrientationSensor.GetDefault();
            if ( simpleOrientationSensor != null ) {
                simpleOrientationSensor.OrientationChanged += MainPage_OrientationChanged;
            }
            else {
                TextSimpleOrientation.Text = @"簡易方位センサーはありません";
            }

            // コンパス
            compass = Compass.GetDefault();
            if ( compass != null ) {
                compass.ReadingChanged += MainPage_ReadingChanged;
            }
            else {
                TextCompass.Text = @"コンパスはありません";
            }

            //try {
            //    geo.DesiredAccuracy = PositionAccuracy.High;
            //    var pos = await geo.GetGeopositionAsync();
            //    TextGeolocation.Text = string.Format( @"{0} {1} {2} {3} {4} {5} {6}",
            //        pos.Coordinate.Latitude, pos.Coordinate.Longitude, pos.Coordinate.Accuracy );
            //}
            //catch ( Exception ex ) {
            //    MessageDialog dlg=new MessageDialog( ex.Message );
            //    dlg.ShowAsync();
            //}
        }
 private void CompassOnReadingChanged(Compass sender, CompassReadingChangedEventArgs args)
 {
     CompassHeading = args.Reading.HeadingMagneticNorth;
 }
 private async Task InitGps()
 {
     // Set your current location.
     var accessStatus = await Geolocator.RequestAccessAsync();
     switch (accessStatus)
     {
         case GeolocationAccessStatus.Allowed:
             // Get the current location.
             Logger.Write("GPS activated");
             _geolocator = new Geolocator
             {
                 DesiredAccuracy = PositionAccuracy.High,
                 DesiredAccuracyInMeters = 5,
                 ReportInterval = 3000,
                 MovementThreshold = 5
             };
             CurrentGeoposition = await _geolocator.GetGeopositionAsync();
             _compass = Compass.GetDefault();
             if (_compass != null)
             {
                 Logger.Write("Compass activated");
                 _compass.ReportInterval = 100;
                 _compass.ReadingChanged += CompassOnReadingChanged;
             }
             break;
         default:
             Logger.Write("Error during GPS activation");
             await new MessageDialog("GPS error, sorry :(").ShowAsync();
             BootStrapper.Current.Exit();
             break;
     }
     _geolocator.PositionChanged += GeolocatorOnPositionChanged;
 }
 async void compass_ReadingChanged( Compass sender, CompassReadingChangedEventArgs args )
 {
     await Dispatcher.RunAsync( Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
     {
     } );
 }
        /// <summary>
        /// This is the click handler for the 'StartTracking' button.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async Task StartTracking()
        {
            // Compass
            _compass = Compass.GetDefault();
            if (_compass != null)
            {
                // Select a report interval that is both suitable for the purposes of the app and supported by the sensor.
                // This value will be used later to activate the sensor.
                uint minReportInterval = _compass.MinimumReportInterval;
                _desiredReportInterval = minReportInterval > 16 ? minReportInterval : 16;

                // Establish the report interval
                _compass.ReportInterval = _desiredReportInterval;
                
                _compass.ReadingChanged += new TypedEventHandler<Compass, CompassReadingChangedEventArgs>(ReadingChanged);

                
            }
            else
            {
                //rootPage.NotifyUser("No compass found", NotifyType.ErrorMessage);
            }


            // Request permission to access location
            var accessStatus = await Geolocator.RequestAccessAsync();

            switch (accessStatus)
            {
                case GeolocationAccessStatus.Allowed:
                    // You should set MovementThreshold for distance-based tracking
                    // or ReportInterval for periodic-based tracking before adding event
                    // handlers. If none is set, a ReportInterval of 1 second is used
                    // as a default and a position will be returned every 1 second.
                    //
                    _geolocator = new Geolocator { MovementThreshold = 2, DesiredAccuracyInMeters = 5 };

                    // Subscribe to PositionChanged event to get updated tracking positions
                    _geolocator.PositionChanged += OnPositionChanged;

                    // Subscribe to StatusChanged event to get updates of location status changes
                    _geolocator.StatusChanged += OnStatusChanged;

                    //_rootPage.NotifyUser("Waiting for update...", NotifyType.StatusMessage);


                    await ShowStatus("Suche aktuelle Position...");


                    break;

                case GeolocationAccessStatus.Denied:
                    await ShowStatus("Zugriff auf Position verweigert");
                    break;

                case GeolocationAccessStatus.Unspecified:
                    await ShowStatus("Fehler bei Ortung");
                    break;
            }
        }
Esempio n. 35
0
        void OnReadingChanged(Sensor sender, CompassReadingChangedEventArgs args)
        {
            var handler = changed;

            if (handler != null)
            {
                var value = ConvertToHeadingNorth(args.Reading);
                var e = new CompassEventArgs(value);
                handler.Invoke(this, e);
            }
        }