Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/214.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 安卓设备的onSensorChanged_Android_Android Sensors - Fatal编程技术网

Android 安卓设备的onSensorChanged

Android 安卓设备的onSensorChanged,android,android-sensors,Android,Android Sensors,我从android设备上获得了长时间和长时间的测试,但我的结果还不够好。我的意思是我的结果是整数:37.0或260.0。。我要双倍号码37.001-37.999 我的代码: // record the compass picture angle turned private float currentDegree = 0f; // device sensor manager private SensorManager mSensorManager; @Override public void

我从android设备上获得了长时间和长时间的测试,但我的结果还不够好。我的意思是我的结果是整数:37.0或260.0。。我要双倍号码37.001-37.999

我的代码:

// record the compass picture angle turned
private float currentDegree = 0f;
// device sensor manager
private SensorManager mSensorManager;

@Override
public void onSensorChanged(SensorEvent event) {
    // TODO Auto-generated method stub
     // get the angle around the z-axis rotated
    float degree = Math.round(event.values[0]);
    tvHeading.setText(Float.toString(degree));
    // create a rotation animation (reverse turn degree degrees)
    RotateAnimation ra = new RotateAnimation(
            currentDegree,
            -degree,
            Animation.RELATIVE_TO_SELF, 0.5f,
            Animation.RELATIVE_TO_SELF,
            0.5f);
    // how long the animation will take place
    ra.setDuration(210);
    // set the animation after the end of the reservation status
    ra.setFillAfter(true);
    // Start the animation
    currentDegree = -degree;
 //   updateWithNewLocation(l);
}
希望对你有所帮助。谢谢

问题解决:需要这样定义度:

float degree = event.values[0];
另一个问题是: 我的结果在0.0到360.0之间,我希望结果的准确度在0.000到6400.999之间

问题也解决了: 要使度数介于0到6400之间,请执行以下操作:

double result =degree * 17.77777778; 
         degree = (float) result;

让我们举个例子:3200必须是180。。180*17.7778正好是3200。无论如何谢谢你。享受:)

学位应定义为

  degree = Math.round(yourValue*100.0)/100.0;
对于十进制乘除100后的2位四舍五入

对于十进制乘除1000后的三位四舍五入

。 .


因此,我已经编辑了答案,请查看。如果有效,请勾选我的答案,并投票支持我的答案。我自己解决了这个问题,我编辑了这个问题。你可以看看。无论如何谢谢。这是硬编码。我要说的是数学逻辑。简单。