forked from organicmaps/organicmaps
Fix direction arrow for landscape orientation when heading is getting from GPS.
This commit is contained in:
parent
85d9ad665c
commit
16dfcfa820
3 changed files with 20 additions and 22 deletions
|
@ -679,14 +679,9 @@ public class MWMActivity extends NvEventQueueActivity implements LocationService
|
|||
@Override
|
||||
public void onCompassUpdated(long time, double magneticNorth, double trueNorth, double accuracy)
|
||||
{
|
||||
@SuppressWarnings("deprecation")
|
||||
final int orientation = getWindowManager().getDefaultDisplay().getOrientation();
|
||||
final double correction = LocationService.getAngleCorrection(orientation);
|
||||
|
||||
magneticNorth = LocationService.correctAngle(magneticNorth, correction);
|
||||
trueNorth = LocationService.correctAngle(trueNorth, correction);
|
||||
|
||||
nativeCompassUpdated(time, magneticNorth, trueNorth, accuracy);
|
||||
double angles[] = { magneticNorth, trueNorth };
|
||||
getLocationService().correctCompassAngles(getWindowManager().getDefaultDisplay(), angles);
|
||||
nativeCompassUpdated(time, angles[0], angles[1], accuracy);
|
||||
}
|
||||
//@}
|
||||
|
||||
|
|
|
@ -579,16 +579,13 @@ public class SearchActivity extends ListActivity implements LocationService.List
|
|||
if (isShowCategories())
|
||||
return;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
final int orientation = getWindowManager().getDefaultDisplay().getOrientation();
|
||||
final double correction = LocationService.getAngleCorrection(orientation);
|
||||
|
||||
final double north = LocationService.correctAngle(trueNorth, correction);
|
||||
double north[] = { trueNorth };
|
||||
m_location.correctCompassAngles(getWindowManager().getDefaultDisplay(), north);
|
||||
|
||||
// if difference is more than 1 degree
|
||||
if (m_north == -1 || Math.abs(m_north - north) > 0.02)
|
||||
if (m_north == -1 || Math.abs(m_north - north[0]) > 0.02)
|
||||
{
|
||||
m_north = north;
|
||||
m_north = north[0];
|
||||
//Log.d(TAG, "Compass updated, north = " + m_north);
|
||||
|
||||
updateDistance();
|
||||
|
|
|
@ -16,6 +16,7 @@ import android.location.LocationManager;
|
|||
import android.net.wifi.WifiManager;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.Display;
|
||||
import android.view.Surface;
|
||||
|
||||
import com.mapswithme.maps.MWMApplication;
|
||||
|
@ -412,12 +413,16 @@ public class LocationService implements LocationListener, SensorEventListener, W
|
|||
|
||||
/// @name Angle correct functions.
|
||||
//@{
|
||||
static public double getAngleCorrection(int screenRotation)
|
||||
@SuppressWarnings("deprecation")
|
||||
public void correctCompassAngles(Display display, double angles[])
|
||||
{
|
||||
double correction = 0;
|
||||
// Do not do any corrections if heading is from GPS service.
|
||||
if (m_drivingHeading >= 0.0)
|
||||
return;
|
||||
|
||||
// correct due to orientation
|
||||
switch (screenRotation)
|
||||
// Correct compass angles due to orientation.
|
||||
double correction = 0;
|
||||
switch (display.getOrientation())
|
||||
{
|
||||
case Surface.ROTATION_90:
|
||||
correction = Math.PI / 2.0;
|
||||
|
@ -430,10 +435,11 @@ public class LocationService implements LocationListener, SensorEventListener, W
|
|||
break;
|
||||
}
|
||||
|
||||
return correction;
|
||||
for (int i = 0; i < angles.length; ++i)
|
||||
angles[i] = correctAngle(angles[i], correction);
|
||||
}
|
||||
|
||||
static public double correctAngle(double angle, double correction)
|
||||
static private double correctAngle(double angle, double correction)
|
||||
{
|
||||
angle += correction;
|
||||
|
||||
|
@ -447,7 +453,7 @@ public class LocationService implements LocationListener, SensorEventListener, W
|
|||
return angle;
|
||||
}
|
||||
|
||||
static double bearingToHeading(double bearing)
|
||||
static private double bearingToHeading(double bearing)
|
||||
{
|
||||
return correctAngle(0.0, bearing * Math.PI / 180.0);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue