2014-10-18 60 views
1

我有Android设备的长和经度,但我的结果不够好。我的意思是我的结果是整型数字:37.0或260.0 ..我想这双号37.001 - 37.999android设备的onSensorChanged

我的代码:

// 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之间,我想6400.999

0.000之间的结果acurate的

问题也解决了: 使0度到6400之间的度数比做:

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

举一个例子:3200必须是180 .. 180 * 17.77777778是3200。不管怎么说,还是要谢谢你。享受:)

回答

0

度应该被定义为

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

十进制乘法后2位数字轮,并通过100

十进制乘法后3位轮划分并除以1000

。 。 。

等等

+0

不起作用的家伙,那也是我的想法。 – RonYamin 2014-10-18 19:37:37

+0

我已编辑答案检查出来。如果它的工作好心地勾选我的答案,并投票我的答案。 – 2014-10-18 20:30:10

+0

我解决了我的问题。你可以看看。不管怎么说,还是要谢谢你。 – RonYamin 2014-10-18 20:45:30