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.

  • 相关阅读:
    网络问题排查
    SpringBoot 自定义注解清除缓存
    MYSQL外键的使用以及优缺点
    Java List
    黑客帝国代码雨
    前端接收字节数据流,显示图片
    何为熔断降级
    spring的线程
    window.open 与 iframe
    js 全部替换
  • 原文地址:https://www.cnblogs.com/boyweb/p/3267011.html
Copyright © 2011-2022 走看看