Windows 8 Study Notes (6)-accelerormeter and geolocation

Source: Internet
Author: User

The device library in winrt contains a variety of device information, such as the sensor gravity accelerator, location information, Bluetooth, and SMS message sending and receiving. The following describes the usage methods:

Sensor gravity accelerator

An accelerormeter gravity accelerator object that obtains the value of X \ Y \ Z for gravity acceleration.

First define this object

Accelerormeter _ accelerometer = accelerometer. getdefault ();

Next, we track the X \ Y \ Z value through the readingchanged event, and perform some logic processing for the shaken shaking event.

Register the readingchanged event

_accelerometer.ReadingChanged += _accelerometer_ReadingChanged;void _accelerometer_ReadingChanged(Accelerometer sender, AccelerometerReadingChangedEventArgs args)        {            Dispatcher.InvokeAsync(CoreDispatcherPriority.Normal, (s, a) =>            {                AccelerometerReading reading = (a.Context as AccelerometerReadingChangedEventArgs).Reading;                tbX.Text = String.Format("{0,5:0.00}", reading.AccelerationX);                tbY.Text = String.Format("{0,5:0.00}", reading.AccelerationY);                tbZ.Text = String.Format("{0,5:0.00}", reading.AccelerationZ);            }, this, e);        }

Register a shaken event

_accelerometer.Shaken += _accelerometer_Shaken;void _accelerometer_Shaken(Accelerometer sender, AccelerometerShakenEventArgs args)        {            Dispatcher.InvokeAsync(CoreDispatcherPriority.Normal, (s, a) =>            {                _shakeCount++;                tbShakeCount.Text = _shakeCount.ToString();            }, this, e);        }

 

Note the following two attributes:

Minimumreportinterval minimum interval for obtaining gravity Sensor report data

Reportinterval is used to set or obtain the report interval value, which reflects the sensitivity of the accelerator.

Geolocation Location Information

Location Information is determined by the Windows location provider by WI-FI and IP address data current geographic information, or can be obtained through GPS. Geolocation can be used to obtain accurate location data.

First define a geolocation object

Geolocator m_geo = new geolocator ();

Next, use the positionchanged and statuschanged events to obtain the location data and the status of the current location device.

M_geo.positionchanged + = m_geo_positionchanged; dispatcher. invokeasync (coredispatcherpriority. normal, (s, A) =>{// obtain the current position object geoposition Pos = (. context as ipositionchangedeventargs ). position; textblock1.text = "latitude:" + POS. coordinate. latitude. tostring (); textblock2.text = "longmargin:" + POS. coordinate. longpolling. tostring (); textblock3.text = "Accuracy:" + POS. coordinate. accuracy. tostring () ;}, this, e );

 

Monitor the status of the current location Locator

m_geo.StatusChanged += m_geo_StatusChanged;void m_geo_StatusChanged(Geolocator sender, StatusChangedEventArgs args)        {            Dispatcher.InvokeAsync(CoreDispatcherPriority.Normal, (s, a) =>            {                PositionStatus status = (a.Context as IStatusChangedEventArgs).Status;                switch (status)                {                    case PositionStatus.Ready:                        textblockStatus1.Text = "Ready";                        break;                    case PositionStatus.Initializing:                        textblockStatus1.Text = "Initializing";                        break;                    case PositionStatus.NoData:                        textblockStatus1.Text = "No data";                        break;                    case PositionStatus.Disabled:                        textblockStatus1.Text = "Disabled";                        break;                    case PositionStatus.NotInitialized:                        textblockStatus1.Text = "Not initialized";                        break;                    case PositionStatus.NotAvailable:                        textblockStatus1.Text = "Not available";                        break;                    default:                        textblockStatus1.Text = "Unexpected status";                        break;                }            }, this, e);        }

There are also two attributes, both of which are enumeration types:

Positionaccuracy: location accuracy, with 0 (default) and 1 (high) Values

Positionstatus: indicates that geolocator provides location data. The above example also lists the corresponding enumeration types.

Today, we will sort out the usage and information acquisition of these two devices, and continue to learn the usage of other devices...

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.