Implement new bearingTrackingMode GPS_NORTH_FACING
This commit is contained in:
@@ -22,7 +22,7 @@ import java.lang.annotation.RetentionPolicy;
|
||||
*/
|
||||
public class MyBearingTracking {
|
||||
|
||||
@IntDef( {NONE, COMPASS, GPS})
|
||||
@IntDef( {NONE, COMPASS, GPS, GPS_NORTH_FACING})
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
public @interface Mode {
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
}
|
||||
|
||||
@@ -356,7 +356,9 @@ public class MyLocationView extends View {
|
||||
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.
|
||||
@@ -383,7 +385,8 @@ public class MyLocationView extends View {
|
||||
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);
|
||||
}
|
||||
@@ -519,7 +522,8 @@ public class MyLocationView extends View {
|
||||
}
|
||||
|
||||
private void toggleGps(boolean enableGps) {
|
||||
toggleGps(enableGps, mapboxMap != null && mapboxMap.getTrackingSettings().isCustomLocationSource());
|
||||
toggleGps(enableGps, mapboxMap != null
|
||||
&& mapboxMap.getTrackingSettings().isCustomLocationSource());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -580,7 +584,8 @@ public class MyLocationView extends View {
|
||||
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);
|
||||
}
|
||||
@@ -616,7 +621,8 @@ public class MyLocationView extends View {
|
||||
compassListener.onResume();
|
||||
} else {
|
||||
compassListener.onPause();
|
||||
if (myLocationTrackingMode == MyLocationTracking.TRACKING_FOLLOW) {
|
||||
if (myLocationTrackingMode == MyLocationTracking.TRACKING_FOLLOW
|
||||
&& myBearingTrackingMode == MyBearingTracking.GPS) {
|
||||
// always face north
|
||||
setCompass(0);
|
||||
} else {
|
||||
@@ -1017,6 +1023,13 @@ public class MyLocationView extends View {
|
||||
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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user