码迷,mamicode.com
首页 > Windows程序 > 详细

Windows Phone 十八、罗盘

时间:2015-06-26 01:44:11      阅读:179      评论:0      收藏:0      [点我收藏+]

标签:

磁力计概述

拥有磁力计硬件支持的设备可以根据磁力计来确定相对于北极的角度

磁力计的访问 API 定义在 Compass 类中

调用方式和加速计类似

1     <Grid Background="White">
2         <Image Source="compass.png" RenderTransformOrigin="0.5,0.5">
3             <Image.RenderTransform>
4                 <CompositeTransform x:Name="rotate" Rotation="1"/>
5             </Image.RenderTransform>
6         </Image>
7     </Grid>
 1         protected override void OnNavigatedTo(NavigationEventArgs e)
 2         {
 3             Compass c = Compass.GetDefault();
 4             if (c == null)
 5             {
 6                 // 不支持罗盘
 7                 return;
 8             }
 9             c.ReadingChanged += async (p1, p2) =>
10             {
11                 // 修改图片的旋转角度;
12                 System.Diagnostics.Debug.WriteLine(p2.Reading.HeadingTrueNorth.Value);
13                 await this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
14                 {
15                     rotate.Rotation = -p2.Reading.HeadingTrueNorth.Value;
16                 });
17             };
18             c.ReportInterval = c.MinimumReportInterval * 10;
19         }

 

Windows Phone 十八、罗盘

标签:

原文地址:http://www.cnblogs.com/includeling/p/4601357.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!