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

Commit

Permalink
Implement new bearingTrackingMode GPS_NORTH_FACING
Browse files Browse the repository at this point in the history
  • Loading branch information
martinhellwigbosch authored and tobrun committed Jan 31, 2018
1 parent 7694c9c commit 0827eb3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*/
public class MyBearingTracking {

@IntDef( {NONE, COMPASS, GPS})
@IntDef( {NONE, COMPASS, GPS, GPS_NORTH_FACING})
@Retention(RetentionPolicy.SOURCE)
public @interface Mode {
}
Expand All @@ -42,4 +42,9 @@ public class MyBearingTracking {
*/
public static final int GPS = 0x00000008;

/**
* Tracking the bearing of the user based on GPS data, but camera always faces north direction
*/
public static final int GPS_NORTH_FACING = 0x0000000B;

}
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,9 @@ protected void onDraw(Canvas canvas) {
foregroundDrawable.draw(canvas);
}
} else if (foregroundBearingDrawable != null && foregroundBounds != null) {
if (myBearingTrackingMode == MyBearingTracking.GPS || compassListener.isSensorAvailable()) {
if (myBearingTrackingMode == MyBearingTracking.GPS
|| myBearingTrackingMode == MyBearingTracking.GPS_NORTH_FACING
|| compassListener.isSensorAvailable()) {
foregroundBearingDrawable.draw(canvas);
} else {
// We are tracking MyBearingTracking.COMPASS, but sensor is not available.
Expand All @@ -383,7 +385,8 @@ public void setTilt(@FloatRange(from = 0, to = 60.0f) double tilt) {
public void setBearing(double bearing) {
this.bearing = bearing;
if (myLocationTrackingMode == MyLocationTracking.TRACKING_NONE) {
if (myBearingTrackingMode == MyBearingTracking.GPS) {
if (myBearingTrackingMode == MyBearingTracking.GPS
|| myBearingTrackingMode == MyBearingTracking.GPS_NORTH_FACING) {
if (location != null) {
setCompass(location.getBearing() - bearing);
}
Expand Down Expand Up @@ -519,7 +522,8 @@ public void onRestoreInstanceState(Parcelable state) {
}

private void toggleGps(boolean enableGps) {
toggleGps(enableGps, mapboxMap != null && mapboxMap.getTrackingSettings().isCustomLocationSource());
toggleGps(enableGps, mapboxMap != null
&& mapboxMap.getTrackingSettings().isCustomLocationSource());
}

/**
Expand Down Expand Up @@ -580,7 +584,8 @@ public void setLocation(Location location) {
this.location = location;
myLocationBehavior.updateLatLng(location);

if (mapboxMap != null && myBearingTrackingMode == MyBearingTracking.GPS
if (mapboxMap != null && (myBearingTrackingMode == MyBearingTracking.GPS
|| myBearingTrackingMode == MyBearingTracking.GPS_NORTH_FACING)
&& myLocationTrackingMode == MyLocationTracking.TRACKING_NONE) {
setBearing(mapboxMap.getCameraPosition().bearing);
}
Expand Down Expand Up @@ -616,7 +621,8 @@ public void setMyBearingTrackingMode(@MyBearingTracking.Mode int myBearingTracki
compassListener.onResume();
} else {
compassListener.onPause();
if (myLocationTrackingMode == MyLocationTracking.TRACKING_FOLLOW) {
if (myLocationTrackingMode == MyLocationTracking.TRACKING_FOLLOW
&& myBearingTrackingMode == MyBearingTracking.GPS) {
// always face north
setCompass(0);
} else {
Expand Down Expand Up @@ -1017,6 +1023,13 @@ void updateLatLng(@NonNull Location location) {
setCompass(0, COMPASS_UPDATE_RATE_MS);
}

if (myBearingTrackingMode == MyBearingTracking.GPS_NORTH_FACING) {
builder.bearing(0);
if (location.hasBearing()) {
setCompass(location.getBearing(), COMPASS_UPDATE_RATE_MS);
}
}

// accuracy
updateAccuracy(location);

Expand Down

0 comments on commit 0827eb3

Please sign in to comment.