[英]Windows Phone 8.1, accelerometer gives wrong reading
I am developing application for windows phone 8.1 and need to detect phone movement. 我正在为Windows Phone 8.1开发应用程序,需要检测手机的移动。
For example, I need to detect one of two scenarios: 例如,我需要检测以下两种情况之一:
and user leans phone up 用户将手机倾斜
And here is the screenshot of application showing acelerometer readings when the phone is in position like on the second picture. 这是该应用程序的屏幕截图,显示了当手机处于第二张图片所示位置时的加速度计读数。
X-Axis, Y-Axis and Z-Axis are same (Same on my device). X轴,Y轴和Z轴相同(在我的设备上相同)。 In the second picture when phone is facing up, X = -0.5317.
在第二张图片中,当手机面朝上时,X = -0.5317。 Looks like that for some reason all axis take this value.
由于某种原因,看起来所有轴都采用该值。
Here is the code. 这是代码。
public RoundPage()
{
this.InitializeComponent();
// ...
this._accelerometer = Accelerometer.GetDefault();
this._accelerometer.ReadingChanged += _accelerometer_ReadingChanged;
}
async void _accelerometer_ReadingChanged(Accelerometer sender, AccelerometerReadingChangedEventArgs args)
{
double xAxis = args.Reading.AccelerationX;
double yAxis = args.Reading.AccelerationY;
double zAxis = args.Reading.AccelerationZ;
await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
AccTextBlock.Text = String.Format("X: {0:f2} Y: {0:f2} Z: {0:f2}",
xAxis,
yAxis,
zAxis);
});
}
What am I doing wrong? 我究竟做错了什么? What is correct way do detect this readings.
什么是正确的方法来检测此读数。
我在String.Format方法中出错,我一直在打印xAxis({0})。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.