forked from organicmaps/organicmaps
[android] Move angle corrections to LocationService.
This commit is contained in:
parent
fcb40b8403
commit
fa25942411
2 changed files with 40 additions and 32 deletions
|
@ -327,42 +327,14 @@ public class MWMActivity extends NvEventQueueActivity implements LocationService
|
|||
nativeLocationUpdated(time, lat, lon, accuracy);
|
||||
}
|
||||
|
||||
private double normalizeAngle(double a)
|
||||
{
|
||||
// normalize magneticNorth into [0, 2PI]
|
||||
if (a < 0.0)
|
||||
a += (2.0*Math.PI);
|
||||
a = a % (2.0*Math.PI);
|
||||
return a;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCompassUpdated(long time, double magneticNorth, double trueNorth, double accuracy)
|
||||
{
|
||||
// correct direction
|
||||
final int screenRotation = getWindowManager().getDefaultDisplay().getOrientation();
|
||||
final int orientation = getWindowManager().getDefaultDisplay().getOrientation();
|
||||
final double correction = LocationService.getAngleCorrection(orientation);
|
||||
|
||||
double correction = 0;
|
||||
|
||||
// correct due to orientation
|
||||
switch (screenRotation)
|
||||
{
|
||||
case Surface.ROTATION_90:
|
||||
correction = Math.PI / 2.0;
|
||||
break;
|
||||
case Surface.ROTATION_180:
|
||||
correction = Math.PI;
|
||||
break;
|
||||
case Surface.ROTATION_270:
|
||||
correction = (3.0 * Math.PI / 2.0);
|
||||
break;
|
||||
}
|
||||
|
||||
magneticNorth += correction;
|
||||
trueNorth += correction;
|
||||
|
||||
magneticNorth = normalizeAngle(magneticNorth);
|
||||
trueNorth = normalizeAngle(trueNorth);
|
||||
magneticNorth = LocationService.correctAngle(magneticNorth, correction);
|
||||
trueNorth = LocationService.correctAngle(trueNorth, correction);
|
||||
|
||||
nativeCompassUpdated(time, magneticNorth, trueNorth, accuracy);
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ import android.os.Bundle;
|
|||
import android.os.PowerManager;
|
||||
import android.os.PowerManager.WakeLock;
|
||||
import android.util.Log;
|
||||
import android.view.Surface;
|
||||
|
||||
import com.mapswithme.maps.MWMApplication;
|
||||
|
||||
|
@ -381,6 +382,41 @@ public class LocationService implements LocationListener, SensorEventListener, W
|
|||
}
|
||||
}
|
||||
|
||||
/// @name Angle correct functions.
|
||||
//@{
|
||||
static public double getAngleCorrection(int screenRotation)
|
||||
{
|
||||
double correction = 0;
|
||||
|
||||
// correct due to orientation
|
||||
switch (screenRotation)
|
||||
{
|
||||
case Surface.ROTATION_90:
|
||||
correction = Math.PI / 2.0;
|
||||
break;
|
||||
case Surface.ROTATION_180:
|
||||
correction = Math.PI;
|
||||
break;
|
||||
case Surface.ROTATION_270:
|
||||
correction = (3.0 * Math.PI / 2.0);
|
||||
break;
|
||||
}
|
||||
|
||||
return correction;
|
||||
}
|
||||
|
||||
static public double correctAngle(double angle, double correction)
|
||||
{
|
||||
angle += correction;
|
||||
|
||||
// normalize angle into [0, 2PI]
|
||||
if (angle < 0.0)
|
||||
angle += (2.0*Math.PI);
|
||||
angle = angle % (2.0*Math.PI);
|
||||
return angle;
|
||||
}
|
||||
//@}
|
||||
|
||||
@Override
|
||||
public void onAccuracyChanged(Sensor sensor, int accuracy)
|
||||
{
|
||||
|
|
Loading…
Add table
Reference in a new issue