zoukankan      html  css  js  c++  java
  • The Compass of the Windows Phone

    I've been involved in the electronic compass of the Windows Phone, and it seems not that difficult.

    The Compass class is in the Microsoft.Devices.Sensors namespace, and must add the referrence before using it.

    private Compass _compass;
    
    //...
    
    if (Compass.IsSupported)
    {
        _compass = new Compass();
        _compass.CurrentValueChanged += CompassCurrentValueChanged;
        _compass.Start();
    }

    That's the initialization of the compass.

    private void CompassCurrentValueChanged(object sender, SensorReadingEventArgs<CompassReading> e)
    {
        Dispatcher.BeginInvoke(() =>
            {
                Direction.Text = e.SensorReading.TrueHeading.ToString(CultureInfo.InvariantCulture);
            });
    }

    The SensorReading has about 4 useful values, if you only want to know where the north is, you can take the TrueHeading value and it's the angle between the north direction and the direction which is the positive y axis direction of your phone.

  • 相关阅读:
    每日日报1
    shazidouhui的使用体验
    水滴的使用体验
    麻雀记的使用体验
    钢镚儿的使用体验
    TD课程通的使用体验
    01 fs模块
    0 mysql 安装
    slot
    vue引入 lodash
  • 原文地址:https://www.cnblogs.com/boyweb/p/3267011.html
Copyright © 2011-2022 走看看