2014-10-18 4 views
1

안드로이드 장치에서 길고 위도가 있지만 결과가 충분하지 않습니다. 나는 내 결과 INT 번호를 의미 : 37.0 또는 260.0에 .. 나는 두 숫자 37.001 싶어 - 37.999안드로이드 장치의 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]; 

또 다른 문제는 다음과 같습니다 내 결과가 360.0-0.0 사이에, 나는 6400.999

에 0.000의 결과 애큐 리트를 원하는 것입니다

문제가 해결됨 : 0-6400 사이의 차수를 지정하는 경우 :

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

예 : 3200은 180이어야합니다. 180 * 17.77777778은 정확히 3200입니다. 고마워. 즐겨 :)

답변

0

도 소수점 곱셈 후 2 자리 라운드

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

정의 1000

의해 소수점 곱셈 후 3 자리 라운드 100

으로 나누어 분할한다. . .

등등

+0

제가 생각했던 것입니다. – RonYamin

+0

나는 답을 편집 해 그것을 체크 아웃했다. 그것이 친절하게 작동한다면 내 대답에 틱하고 또한 내 대답에 투표하십시오. –

+0

나는 그 자체로 내가 문제를 해결했다. 보세요. 고마워. – RonYamin

관련 문제