I'm actually coding an application on Android and I need to point a certain direction, explaination, I have a position that is fixed and the position of my smartphone (the two in Longitude Latitude) and I want to point an arrow to the direction between the two. So I searched like hell, I have a compass that works perfectly and I tried to change pointing direction by changing the north direction get by the getRotationMatrix stuff but well after loosing my brain trying I don't know what to do xD So yeah I need some ideas and hints.
Here's my code just in case (I just past the onSensorChanged func the rest is just basic initialisations)
@Override
public void onSensorChanged(SensorEvent event) {
if (event.sensor == mAccelerometer) {
System.arraycopy(event.values, 0, mLastAccelerometer, 0, event.values.length);
mLastAccelerometerSet = true;
} else if (event.sensor == mMagnetometer) {
System.arraycopy(event.values, 0, mLastMagnetometer, 0, event.values.length);
mLastMagnetometerSet = true;
}
if (mLastAccelerometerSet && mLastMagnetometerSet) {
SensorManager.getRotationMatrix(mR, null, mLastAccelerometer, mLastMagnetometer);
SensorManager.getOrientation(mR, mOrientation);
float azimuthInRadians = mOrientation[0];
float azimuthInDegress = (float)(Math.toDegrees(azimuthInRadians)+360)%360;
RotateAnimation ra = new RotateAnimation(
mCurrentDegree,
-azimuthInDegress,
Animation.RELATIVE_TO_SELF, 0.5f,
Animation.RELATIVE_TO_SELF,
0.5f);
ra.setDuration(250);
ra.setFillAfter(true);
mPointer.startAnimation(ra);
mCurrentDegree = -azimuthInDegress;
}
}