Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,19 @@ void removeCameraListener(OnCameraAnimationsValuesChangeListener listener) {
cameraListeners.remove(listener);
}

void feedNewLocation(@NonNull Location newLocation, @NonNull CameraPosition currentCameraPosition,
boolean isGpsNorth) {
/**
* Returns whether location has to be updated manually.
*/
boolean feedNewLocation(@NonNull Location newLocation, @NonNull CameraPosition currentCameraPosition,
boolean isGpsNorth) {
if (previousLocation == null) {
previousLocation = newLocation;
locationUpdateTimestamp = SystemClock.elapsedRealtime();
return true;
}

if (invalidUpdateInterval()) {
return;
return false;
}

LatLng previousLayerLatLng = getPreviousLayerLatLng();
Expand All @@ -80,11 +84,17 @@ void feedNewLocation(@NonNull Location newLocation, @NonNull CameraPosition curr
playAllLocationAnimators(getAnimationDuration());

previousLocation = newLocation;

return false;
}

void feedNewCompassBearing(float targetCompassBearing, @NonNull CameraPosition currentCameraPosition) {
/**
* Returns whether compass bearing has to be updated manually.
*/
boolean feedNewCompassBearing(float targetCompassBearing, @NonNull CameraPosition currentCameraPosition) {
if (previousCompassBearing < 0) {
previousCompassBearing = targetCompassBearing;
return true;
}

float previousLayerBearing = getPreviousLayerCompassBearing();
Expand All @@ -94,6 +104,8 @@ void feedNewCompassBearing(float targetCompassBearing, @NonNull CameraPosition c
playCompassAnimators(COMPASS_UPDATE_RATE_MS);

previousCompassBearing = targetCompassBearing;

return false;
}

private final ValueAnimator.AnimatorUpdateListener layerLatLngUpdateListener =
Expand Down Expand Up @@ -251,7 +263,7 @@ private long getAnimationDuration() {
animationDuration = 0;
} else {
animationDuration = (int) ((locationUpdateTimestamp - previousUpdateTimeStamp) * 1.1f)
/*make animation slightly longer*/;
/*make animation slightly longer*/;
}
return animationDuration;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -505,12 +505,19 @@ private void updateLocation(final Location location) {
staleStateManager.updateLatestLocationTime();
CameraPosition currentCameraPosition = mapboxMap.getCameraPosition();
boolean isGpsNorth = getCameraMode() == CameraMode.TRACKING_GPS_NORTH;
locationLayerAnimator.feedNewLocation(location, currentCameraPosition, isGpsNorth);
boolean forceLocationUpdate = locationLayerAnimator.feedNewLocation(location, currentCameraPosition, isGpsNorth);
if (forceLocationUpdate) {
locationLayer.onNewLatLngValue(new LatLng(location.getLatitude(), location.getLongitude()));
locationLayer.onNewGpsBearingValue(location.getBearing());
}
locationLayer.updateAccuracyRadius(location);
}

private void updateCompassHeading(float heading) {
locationLayerAnimator.feedNewCompassBearing(heading, mapboxMap.getCameraPosition());
boolean forceCompassUpdate = locationLayerAnimator.feedNewCompassBearing(heading, mapboxMap.getCameraPosition());
if (forceCompassUpdate) {
locationLayer.onNewCompassBearingValue(heading);
}
}

/**
Expand Down