Develop an electronic compass using Windows Phone 8.1

Source: Internet
Author: User
Tags time interval

Compass, it is estimated that I do not introduce too much, have learned the physics of junior high school know, whether it is a compass, or refers to the North needle, its essence is used to identify the direction.

The operation of electronic Compass Wei sensor is not complicated, is mainly two angles:

1. The angle between the current direction and the magnetic north;

2. The angle between the current direction and the north.

At the same time, we also understand that the geographical north and the geomagnetic North Pole is not coincident, the existence of deflection angle. When reading the electronic compass data, it is preferable to read the angle of the North Pole, and if the angle of the North Pole is not read, then the angle data of the magnetic North Pole are read.

The Compassreading class (located in the Windows.Devices.Sensors namespace) encapsulates the data that is read from an electronic compass.

1, Headingmagneticnorth properties: To obtain the current direction and magnetic north of the number of clip angles.

2. Headingtruenorth property: This property gets the true North angle, which is the geographical angle. We notice that its type is double, that is, the Nullable<double>, which indicates that the value is likely to be null, that is, it is possible to get the values of the north-South angle. In use, we can first determine whether the North point is null, if it is not NULL to use this value, if NULL is the value of the magnetic North Point.

3, headingaccuracy attribute: The accuracy of the compass reading, if the reading accuracy is higher, it returns high. Our application can check whether this property is high at the right time, and if not, consider prompting the user to calibrate the compass.

Referring to the calibration, it is necessary to say that the calibration compass is not required to prompt the system, the application can also not be prompted. You can prompt the user for calibration only considering the user experience problem. The calibration method is very simple, whether you are using WP's own map application, or other third-party applications, or your own development of the application. As long as in the use of the compass, you take the mobile phone, in the air to do several "8" zigzag back and forth to move it, do not need to wait for the hint, as long as the compass can be used to calibrate the place at any time.

Electronic Compass API encapsulated in the Windows.Devices.Sensors.Compass class, the WP API all sensor calls are very simple, first get to a sensor class instance, generally through the Getdefault method (static method) can return, Then set the time interval for the reads, in milliseconds, if you want to read the data every second, set the Reportinterval to 1000, but this interval cannot be less than the value specified by the Minimumreportinterval property, which should be noted, Set to 20 milliseconds above the interval, the effect is good, of course, it depends on the actual situation you use.

Finally, the Readingchanged event is handled, and when new data is read, the event is raised and the newly read data is passed to the event, and we can get the latest readings from the event arguments.

Well, the theory is always abstract, the following for everyone to see what I do a simple compass, is indeed very simple, I hope we do not laugh, because I am more than vegetables, so even the main page of the compass is also a direct draw with the XAML.

The previous effect chart is first.

See, humble, there is no way, people poor is so, to eat vegetarian clothes. Compass background I draw in a few circles, indicating the direction of the pointer is made with the path element.

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/OS/extra/

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.