【问题标题】:onSensorChanged of android deviceandroid设备的onSensorChanged
【发布时间】:2014-10-18 19:07:24
【问题描述】:

我有来自 android 设备的 long 和 lat,但我的结果还不够好。我的意思是我的结果是整数: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.77777778 正好是 3200。不管怎么说,还是要谢谢你。享受:)

【问题讨论】:

    标签: android android-sensors


    【解决方案1】:

    度数应该定义为

      degree = Math.round(yourValue*100.0)/100.0;
    

    小数点后两位数乘除以100

    小数点后的 3 位取整除以 1000

    。 . .

    以此类推

    【讨论】:

    • 我已经编辑了答案,请查看。如果它有效,请勾选我的答案并投票给我的答案。
    • 我自己解决了我编辑了这个问题。你可以看看。无论如何谢谢。
    • 这是硬编码。我提到你的数学逻辑。简单。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多