protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            DisplayInformation.AutoRotationPreferences = DisplayOrientations.Landscape;
            await StartCamera();

            _compass = Compass.GetDefault();
            if (_compass != null)
            {
                _compass.ReadingChanged += CompassReadingChanged;
                CompassChanged(_compass.GetCurrentReading());
            }

            _gps = new Geolocator();
            _gps.MovementThreshold = _movementThreshold;
            _gps.PositionChanged  += GpsPositionChanged;

            if (_gps.LocationStatus == PositionStatus.Ready)
            {
                var pos = await _gps.GetGeopositionAsync();

                if (pos != null && pos.Coordinate != null && pos.Coordinate.Point != null)
                {
                    GpsChanged(pos.Coordinate.Point.Position);
                }
            }
        }
Пример #2
0
        private async void Locate_Me_Btn_Click(object sender, RoutedEventArgs e)
        {
            var cmp = Compass.GetDefault();

            if (cmp == null)
            {
                return;
            }
            try
            {
                Geolocator  geolocator  = new Geolocator();
                Geoposition geoposition = await geolocator.GetGeopositionAsync();

                Postavi_Stranicu(-1, "Moja lokacija", geoposition.Coordinate.Point.Position.Latitude, geoposition.Coordinate.Point.Position.Longitude);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Greška pri uzimanju lokacije uređaja " + "(" + ex.Message + ")");

                #region Poruka za korisnika
                MessageDialog ms          = new MessageDialog("Vaše lokacijske postavke su isključene.\nŽelite li uključiti lokacijske postavke uređaja?", Fixed.App_Name);
                UICommand     settingsBtn = new UICommand("da");
                settingsBtn.Invoked = settingsBtnClick;
                ms.Commands.Add(settingsBtn);
                UICommand noBtn = new UICommand("ne");
                noBtn.Invoked = NoBtnClick;
                ms.Commands.Add(noBtn);
                await ms.ShowAsync();

                #endregion
            }
        }
Пример #3
0
        void OnLoaded(object sender, Windows.UI.Xaml.RoutedEventArgs e)
        {
            // We use the compass here but the pattern is the same for other sensors
            // like;
            //
            // Accelerometer
            // Altimeter
            // Barometer
            // Gyrometer
            // Inclinometer
            // LightSensor
            // Magnetometer
            // Orientation
            // Pedometer
            // Proximity
            // SimpleOrientation
            // Basic pattern is get sensor (if present), ask it for reading (polling if you
            // like) and/or ask it to tell you when the reading changes.
            this.compass = Compass.GetDefault();

            if (this.compass != null)
            {
                // We could ask the compass to report more frequently but we don't
                // here
                this.compass.ReportInterval = compass.MinimumReportInterval;

                // Tell me when it changes.
                this.compass.ReadingChanged += OnCompassReadingChanged;

                var reading = this.compass.GetCurrentReading();

                this.DisplayReading(reading);
            }
        }
Пример #4
0
        public TouristToolkit()
        {
            blobUrl = "";
            this.InitializeComponent();
            i      = 0;
            li     = new List <Scrap>();
            li2    = new List <PointerViewAR>();
            li3    = new List <Pointer>();
            id     = new List <string>();
            or     = OrientationSensor.GetDefault();
            myBool = false;
            c      = Compass.GetDefault();
            try
            {
                c.ReportInterval   = 4;
                c.ReadingChanged  += C_ReadingChanged;
                or.ReportInterval  = 4;
                or.ReadingChanged += Or_ReadingChanged;
            }
            catch
            { }
            this.InitializeComponent();
            PreviewControl.Loaded += PreviewControl_Loaded;

            Application.Current.Suspending += Application_Suspending;
        }
Пример #5
0
        /// <summary>
        /// Initialize settings for Compass.
        /// </summary>
        private void InitializeCompass()
        {
            txtTitle.Text = String.Format(CultureInfo.CurrentCulture, App.LoadString("Test"), App.LoadString("Compass"));

            try
            {
                // Instantiate the Compass.
                _compass = Compass.GetDefault();

                if (_compass == null)
                {
                    // The device on which the application is running does not support the compass sensor
                    txtStatus.Text = String.Format(CultureInfo.CurrentCulture, App.LoadString("NotSupported"), App.LoadString("Compass"));
                }
                else
                {
                    // Add ReadingChanged event handler
                    _compass.ReadingChanged += compass_ReadingChanged;
                }
            }
            catch
            {
                _compass       = null;
                txtStatus.Text = App.LoadString("Error");
            }
        }
        /// <summary>
        /// Initializes a new instance of the DeviceMotionImplementation class.
        /// </summary>
        public DeviceMotionImplementation()
        {
            try
            {
                accelerometer = Accelerometer.GetDefault();
                gyrometer     = Gyrometer.GetDefault();
                compass       = Compass.GetDefault();

#if WINDOWS_PHONE_APP
                magnetometer = Magnetometer.GetDefault();
#endif
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }

            sensorStatus = new Dictionary <MotionSensorType, bool>()
            {
                { MotionSensorType.Accelerometer, false },
                { MotionSensorType.Gyroscope, false },
                { MotionSensorType.Magnetometer, false },
                { MotionSensorType.Compass, false }
            };
        }
Пример #7
0
        /// <summary>
        ///     Starts the timer to update map objects and the handler to update position
        /// </summary>
        public static async Task InitializeDataUpdate()
        {
            #region Compass management
            SettingsService.Instance.PropertyChanged += (object sender, PropertyChangedEventArgs e) =>
            {
                if (e.PropertyName == nameof(SettingsService.Instance.MapAutomaticOrientationMode))
                {
                    switch (SettingsService.Instance.MapAutomaticOrientationMode)
                    {
                    case MapAutomaticOrientationModes.Compass:
                        _compass = Compass.GetDefault();
                        _compass.ReportInterval  = Math.Max(_compass.MinimumReportInterval, 50);
                        _compass.ReadingChanged += compass_ReadingChanged;
                        break;

                    case MapAutomaticOrientationModes.None:
                    case MapAutomaticOrientationModes.GPS:
                    default:
                        if (_compass != null)
                        {
                            _compass.ReadingChanged -= compass_ReadingChanged;
                            _compass = null;
                        }
                        break;
                    }
                }
            };
            //Trick to trigger the PropertyChanged for MapAutomaticOrientationMode ;)
            SettingsService.Instance.MapAutomaticOrientationMode = SettingsService.Instance.MapAutomaticOrientationMode;
            #endregion
            Busy.SetBusy(true, Resources.CodeResources.GetString("GettingGpsSignalText"));
            await LocationServiceHelper.Instance.InitializeAsync();

            LocationServiceHelper.Instance.PropertyChanged += LocationHelperPropertyChanged;
            // Before starting we need game settings
            GameSetting =
                await
                DataCache.GetAsync(nameof(GameSetting), async() => (await _client.Download.GetSettings()).Settings,
                                   DateTime.Now.AddMonths(1));

            // Update geolocator settings based on server
            LocationServiceHelper.Instance.UpdateMovementThreshold(GameSetting.MapSettings.GetMapObjectsMinDistanceMeters);
            if (_heartbeat == null)
            {
                _heartbeat = new Heartbeat();
            }
            await _heartbeat.StartDispatcher();

            // Update before starting timer
            Busy.SetBusy(true, Resources.CodeResources.GetString("GettingUserDataText"));
            //await UpdateMapObjects();
            await UpdateInventory();
            await UpdateItemTemplates();

            if (PlayerProfile != null && PlayerStats != null)
            {
                Busy.SetBusy(false);
            }
        }
Пример #8
0
        /// <summary>
        /// Start the Geolocator and the Compass
        /// </summary>
        /// <returns></returns>
        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.
                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;


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


                break;

            case GeolocationAccessStatus.Denied:
                await ShowStatus("Zugriff auf Position verweigert", StatusType.Error, 5, 0);

                break;

            case GeolocationAccessStatus.Unspecified:
                await ShowStatus("Fehler bei Ortung", StatusType.Error, 5, 0);

                break;
            }
        }
Пример #9
0
 private void InitializeCompass()
 {
     _compass = Compass.GetDefault();
     if (_compass != null)
     {
         _compass.ReadingChanged += CompassOnCurrentValueChanged;
     }
 }
Пример #10
0
 private void OnGetCompass2(object sender, RoutedEventArgs e)
 {
     compass = Compass.GetDefault();
     compass.ReportInterval  = compass.MinimumReportInterval;
     compass.ReadingChanged += (sender1, e1) =>
     {
         this.DefaultViewModel["CompassResult"] = GetCompassResult(e1.Reading);
     };
 }
Пример #11
0
 public BindableCompass()
 {
     _compass = Compass.GetDefault();
     if (_compass != null)
     {
         _compass.ReadingChanged += compass_CurrentValueChanged;
         AssignCurrentValue(_compass.GetCurrentReading());
     }
 }
Пример #12
0
        public GeolocationService()
        {
            _geolocator = new Geolocator
            {
                ReportInterval = InactiveUpdateInterval
            };

            _compass = Compass.GetDefault();
        }
Пример #13
0
        /// <summary>
        ///     Starts the timer to update map objects and the handler to update position
        /// </summary>
        public static async Task InitializeDataUpdate()
        {
            if (SettingsService.Instance.IsCompassEnabled)
            {
                _compass = Compass.GetDefault();
                if (_compass != null)
                {
                    _compassTimer = new DispatcherTimer
                    {
                        Interval = TimeSpan.FromMilliseconds(Math.Max(_compass.MinimumReportInterval, 50))
                    };
                    _compassTimer.Tick += (s, e) =>
                    {
                        if (SettingsService.Instance.IsAutoRotateMapEnabled)
                        {
                            HeadingUpdated?.Invoke(null, _compass.GetCurrentReading());
                        }
                    };
                    _compassTimer.Start();
                }
            }
            _geolocator = new Geolocator
            {
                DesiredAccuracy         = PositionAccuracy.High,
                DesiredAccuracyInMeters = 5,
                ReportInterval          = 1000,
                MovementThreshold       = 5
            };

            Busy.SetBusy(true, Resources.CodeResources.GetString("GettingGpsSignalText"));
            Geoposition = Geoposition ?? await _geolocator.GetGeopositionAsync();

            GeopositionUpdated?.Invoke(null, Geoposition);
            _geolocator.PositionChanged += GeolocatorOnPositionChanged;
            // Before starting we need game settings
            GameSetting =
                await
                DataCache.GetAsync(nameof(GameSetting), async() => (await _client.Download.GetSettings()).Settings,
                                   DateTime.Now.AddMonths(1));

            // Update geolocator settings based on server
            _geolocator.MovementThreshold = GameSetting.MapSettings.GetMapObjectsMinDistanceMeters;
            if (_heartbeat == null)
            {
                _heartbeat = new Heartbeat();
            }
            await _heartbeat.StartDispatcher();

            // Update before starting timer
            Busy.SetBusy(true, Resources.CodeResources.GetString("GettingUserDataText"));
            //await UpdateMapObjects();
            await UpdateInventory();
            await UpdateItemTemplates();

            Busy.SetBusy(false);
        }
 public MainPage()
 {
     InitializeComponent();
     _compass = Compass.GetDefault();
     if (_compass != null)
     {
         _compass.ReportInterval  = Math.Max(16, _compass.MinimumReportInterval);
         _compass.ReadingChanged += Compass_ReadingChanged;
     }
 }
        // 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;
            }
        }
Пример #16
0
        private void Compas_Click(object sender, RoutedEventArgs e)
        {
            Compass c = Compass.GetDefault();

            if (c != null)
            {
                c.ReadingChanged += C_ReadingChanged;
            }

            //Com.Text = c.GetCurrentReading().HeadingTrueNorth.ToString() ?? "error";
        }
Пример #17
0
 private void InitCompass()
 {
     m_compass = Compass.GetDefault();
     if (m_compass != null)
     {
         // Establish the report interval for all scenarios
         uint minReportInterval = m_compass.MinimumReportInterval;
         uint reportInterval    = minReportInterval > 16 ? minReportInterval : 16;
         m_compass.ReportInterval  = reportInterval;
         m_compass.ReadingChanged += CompassReadingChanged;
     }
 }
        private void OnLoaded(object sender, RoutedEventArgs e)
        {
            compass = Compass.GetDefault();
            if (compass != null)
            {
                uint minReportInterval = compass.MinimumReportInterval;
                uint reportInterval    = minReportInterval > 16 ? minReportInterval : 16;
                compass.ReportInterval = reportInterval;

                compass.ReadingChanged += OnCompassReadingChanged;
            }
        }
Пример #19
0
 public async void LoadPage()
 {
     Compass = Compass.GetDefault();
     if (Compass != null)
     {
         Compass.ReadingChanged += Compass_ReadingChanged;
     }
     ActiveNavigationMode = false;
     geolocator           = GeoLocate;
     Map = View.MapView.MapControl;
     await AppCore.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, LocateUser);
 }
Пример #20
0
            public CompassSensor(string id) : base(id)
            {
                type     = id;
                _compass = Compass.GetDefault();

                if (_compass != null)
                {
                    uint minReportInterval = _compass.MinimumReportInterval;
                    uint reportInterval    = minReportInterval > 16 ? minReportInterval : 16;
                    _compass.ReportInterval  = reportInterval;
                    _compass.ReadingChanged += new TypedEventHandler <Compass, CompassReadingChangedEventArgs>(ReadingChanged);
                }
            }
Пример #21
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;
     }
 }
Пример #22
0
        private void CTPstrbtn_Click(object sender, RoutedEventArgs e)
        {
            _compass = Compass.GetDefault();

            if (_compass != null)
            {
                uint minReportInterval = _compass.MinimumReportInterval;
                uint reportInterval    = minReportInterval > 16 ? minReportInterval : 16;
                _compass.ReportInterval  = reportInterval;
                _compass.ReadingChanged += new TypedEventHandler <Compass, CompassReadingChangedEventArgs>(ReadingChanged);
                complitedtest            = true;
            }
        }
Пример #23
0
        private void ResolveSensorInfo()
        {
            if (Windows.Devices.Sensors.Accelerometer.GetDefault() != null)
            {
                HasAccelerometerSensor = true;
            }

            if (Compass.GetDefault() != null)
            {
                HasCompass = true;
            }

            try
            {
                if (Gyrometer.GetDefault() != null)
                {
                    HasGyroscopeSensor = true;
                }
            }
            catch (Exception e)
            {
                /* Older phone software had a bug causing the
                 * Gyrometer.GetDefault() to throw a file operation
                 * exception.
                 */
                System.Diagnostics.Debug.WriteLine(e.ToString());
                HasGyroscopeSensor = Microsoft.Devices.Sensors.Gyroscope.IsSupported;
            }

            if (Windows.Devices.Sensors.Inclinometer.GetDefault() != null)
            {
                HasInclinometerSensor = true;
            }

            /* Motion API requires both magnetometer (compass) and
             * accelerometer sensors. Gyroscope sensor is used for more
             * accurate results but is not mandatory.
             */
            MotionApiAvailable = Microsoft.Devices.Sensors.Motion.IsSupported;

            if (Windows.Devices.Sensors.OrientationSensor.GetDefault() != null)
            {
                HasOrientationSensor = true;
            }

            // ProximityDevice is NFC
            if (ProximityDevice.GetDefault() != null)
            {
                HasProximitySensor = true;
            }
        }
        public void OnGetCompass()
        {
            Compass sensor = Compass.GetDefault();

            if (sensor != null)
            {
                CompassReading reading = sensor.GetCurrentReading();
                CompassInfo = $"magnetic north: {reading.HeadingMagneticNorth} real north: {reading.HeadingTrueNorth} accuracy: {reading.HeadingAccuracy}";
            }
            else
            {
                CompassInfo = "Compass not found";
            }
        }
        public MapViewModel(IBeaconWatcher beaconWatcher, IBeaconGeolocator beaconGeolocator, IMapServiceClient mapServiceClient)
        {
            _beaconWatcher    = beaconWatcher;
            _beaconGeolocator = beaconGeolocator;
            _mapServiceClient = mapServiceClient;

            _compass = Compass.GetDefault();

            _compassTimer = new DispatcherTimer()
            {
                Interval = TimeSpan.FromMilliseconds(30)
            };
            _compassTimer.Tick += _compassTimer_Tick;
        }
Пример #26
0
        private void ToggleCompass()
        {
            if (this.SensorSwitches.M != null)
            {
                if (this.SensorSwitches.M.Value > 0)
                {
                    if (this.compass == null)
                    {
                        this.compass = Compass.GetDefault();
                    }

                    if (this.compass != null)
                    {
                        this.compass.ReportInterval = Math.Max(
                            Math.Max(baseMinimum, (uint)this.SensorSwitches.Interval),
                            this.compass.MinimumReportInterval);

                        if (this.SensorSwitches.M.Value != 1)
                        {
                            this.compass.ReadingChanged += this.NewCom;
                        }

                        this[COMPASS].Id    = this.SensorSwitches.Id;
                        this[COMPASS].Delta = this.SensorSwitches.Delta;

                        if (this.SensorSwitches.M.Value != 3)
                        {
                            this.SensorSwitches.M = null;
                            this.NewCom(this.compass, null);
                        }
                        else
                        {
                            this.SensorSwitches.M = null;
                        }
                    }
                }
                else
                {
                    if (this.compass != null)
                    {
                        this.compass.ReadingChanged -= this.NewCom;
                        this.NewCom(null, null);
                    }

                    this.SensorSwitches.M = null;
                }
            }
        }
Пример #27
0
        private async void OnGetCompass(object sender, RoutedEventArgs e)
        {
            Compass compass = Compass.GetDefault();

            if (compass != null)
            {
                CompassReading reading = compass.GetCurrentReading();

                this.DefaultViewModel["CompassResult"] = GetCompassResult(reading);
            }
            else
            {
                var dlg = new MessageDialog("No compass found");
                await dlg.ShowAsync();
            }
        }
Пример #28
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;
        }
Пример #29
0
        public Scenario1_DataEvents()
        {
            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);
            }
        }
        /// <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 }
            };
        }