Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[android] #5438 - fixes compass tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
tobrun committed Jul 12, 2016
1 parent bf23cde commit 812b3b0
Showing 1 changed file with 4 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ public void setMyBearingTrackingMode(@MyBearingTracking.Mode int myBearingTracki
compassListener.onPause();
if (myLocationTrackingMode == MyLocationTracking.TRACKING_FOLLOW) {
// always face north
gpsDirection = 0;
gpsDirection = bearing;
setCompass(gpsDirection);
}
}
Expand Down Expand Up @@ -558,7 +558,7 @@ public void onSensorChanged(SensorEvent event) {

SensorManager.getRotationMatrix(mR, mI, mGData, mMData);
SensorManager.getOrientation(mR, mOrientation);
setCompass((int) (mOrientation[0] * 180.0f / Math.PI));
setCompass(mCurrentDegree = (int) (mOrientation[0] * 180.0f / Math.PI));
mCompassUpdateNextTimestamp = currentTime + UPDATE_RATE_MS;
}

Expand Down Expand Up @@ -715,8 +715,8 @@ void updateLatLng(@NonNull final Location location) {
latLng = new LatLng(location);

// update LatLng direction
if (location.hasBearing()) {
gpsDirection = clamp(location.getBearing() - (float) mapboxMap.getCameraPosition().bearing);
if (myBearingTrackingMode == MyBearingTracking.GPS && location.hasBearing()) {
gpsDirection = location.getBearing();
setCompass(gpsDirection);
}

Expand Down Expand Up @@ -748,17 +748,6 @@ void updateLatLng(@NonNull final Location location) {
latLng = interpolatedLocation;
}

private float clamp(float direction) {
float diff = previousDirection - direction;
if (diff > 180.0f) {
direction += 360.0f;
} else if (diff < -180.0f) {
direction -= 360.f;
}
previousDirection = direction;
return direction;
}

@Override
void invalidate() {
screenLocation = projection.toScreenLocation(latLng);
Expand Down

0 comments on commit 812b3b0

Please sign in to comment.