2014-10-18 35 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