나침반처럼 특정 좌표를 가리키는 화살표를 만들려고합니다.RotateAnimation을 사용하여 특정 위치를 가리키는 Android
//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);
:
//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를 사용 : 나는 방위각을 계산하기 위해 휴대 전화에서 Sensor.TYPE_ACCELEROMETER
및 Sensor.TYPE_MAGNETIC_FIELD
을 사용하고 (이 질문 Using orientation sensor to point towards a specific location에서 참조했다)
그러나 4 개의 다른 targetLocations를 각각 북동쪽의 남쪽과 서쪽 방향으로 테스트했습니다. 화살표는 동서쪽 위치 만 올바르게 가리 킵니다. 방향이 북쪽과 남쪽 인 경우 화살표는 180도 회전하여 완전히 반대 방향으로 향하게합니다. 회전에 180도를 추가하면 화살표가 북쪽이나 남쪽의 위치를 올바르게 가리키지 만 동쪽과 서쪽 위치는 틀립니다. 정말 실망스럽고 이것은 내게 전혀 이해가되지 않습니다.
누군가 나를 도와 줄 수 있다면 정말 감사 할 것입니다! 미리 감사드립니다!