Android compass example does not seem to work in landscape mode
I have developed a compass based on this example: http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/graphics/Compass.html
Since my app only operates in landscape mode so will the compass. However, it seems as this code does not function correctly in landscape mode. North points more towards east. If i run the Android example code 开发者_JAVA技巧I get the same issue.
Has anyone else noticed this and even better does anyone have a solution?
By the way, I am testing this on a Nexus One. Not sure if this is a phone related issue.
Best regards
P
You have to subtract 90 degrees from the rotation because the magnometer is on the top of the phone.
int test = getResources().getConfiguration().orientation;
if(Configuration.ORIENTATION_LANDSCAPE == test) {
rotation = -90f;
}
else {
rotation = 0f;
}
canvas.rotate((float) (-Math.toDegrees(mOrientation[0]) + rotation ));
精彩评论