コンパスのような特定の座標を指す矢印を作成しようとしています。私は(私はこの質問Using orientation sensor to point towards a specific locationからの基準を取った)方位角を計算するために携帯電話からSensor.TYPE_ACCELEROMETER
とSensor.TYPE_MAGNETIC_FIELD
を使用しています :特定の場所を指すRotateAnimationを使用しているAndroid
//calculate RotationMatrix
if (gravity != null && geomag != null) {
boolean success = SensorManager.getRotationMatrix(inR, I,
gravity, geomag);
if (success) {
SensorManager.getOrientation(inR, orientVals);
azimuth = Math.toDegrees(orientVals[0]);
pitch = Math.toDegrees(orientVals[1]);
roll = Math.toDegrees(orientVals[2]);
}
}
azimuth += geomagneticField.getDeclination();
//azimuth = Math.round(sensorEvent.values[0]);
float bearing = lastLocation.bearingTo(targetLocation);
float angle = (float) azimuth + bearing;
私はその後、矢印自体の回転を作成するためにRotatateAnimationを使用します。
//the +90 below is because the ImageView arrow is pointing towards left by default
RotateAnimation animation = new RotateAnimation(
-(angle+90),
-(angle+90),
Animation.RELATIVE_TO_SELF, 0.5f,
Animation.RELATIVE_TO_SELF,
0.5f);
しかし、東西南北方向にそれぞれ4つの異なるtargetLocationsをテストしました。矢印は東西の位置を正しく指しています。方向が北と南の場合、矢印は180度回転します。つまり、矢印は完全に反対方向を指します。回転に180度追加すると、矢印は北または南の位置を正しく指しますが、東と西の位置は間違っています。 これは本当にイライラしており、これは私には絶対に意味がありません。
誰かが私をここで助けてくれたら本当に本当に感謝しています!前もって感謝します!