You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
Repository navigation
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
Open User tracking mode demo (i.e. MyLocationTrackingModeActivity) in Mapbox Android SDK TestApp.
In top right dropdown, select Compass bearing.
Expected behavior
Bearing indicator starts responding immediately and correctly indicates the device's bearing.
Actual behavior
Bearing indicator remains stuck indicating north for multiple seconds. The indicator updates occasionally but eratically, and does not correctly indicate the device's bearing for the majority of the time.
There are two issues at play here:
The logic in the CompassListener#onSensorChanged(SensorEvent) callback is throttled according to UPDATE_RATE_MS. Two types of events (accelerometer and magnetometer) are sent to this callback, but the arrival of either one subsequently blocks processing for UPDATE_RATE_MS. In my testing, it was common for e.g. multiple seconds of magnetometer events only to be processed. This would simultaneously block any accelerometer data for that period of time. If this happens at the start when either sensor value array is zeroed, the bearing output remains zero until both types of sensor data are processed. If this happens at a later time, either the magnetometer or the accelerometer data may become multiple seconds out-of-date, resulting in an incorrect bearing calculation.
The bearing indicator rotation is reflected in MyLocationView#onDraw(Canvas). MyLocationView#setCompass(float)starts an animator to update the bearing indicator rotation. However, this animator does not call MyLocationView#invalidate() during the animation. This results in the bearing indicator updating only when something else coincidentally invalidates MyLocationView.
On a somewhat related note, the bearing indicator animation may appear more continuous if the animation duration matches the update rate, instead of using a seemingly arbitrary value of 375 ms.
Activity
[android] mapbox#5335 - Always record latest accelerometer and magnet…
[android] mapbox#5335 - Invalidate MyLocationView during bearing indi…
justasm commentedon Jun 13, 2016
On a somewhat related note, the bearing indicator animation may appear more continuous if the animation duration matches the update rate, instead of using a seemingly arbitrary value of
375ms.[android] #5335 - Always record latest accelerometer and magnetometer…
[android] #5335 - Invalidate MyLocationView during bearing indicator …
tobrun commentedon Jun 17, 2016
Still need to pick up suggestion in #5335 (comment) to close this issue.
cammace commentedon Nov 16, 2016
The bearing indicator animation has been changed recently to be more continuous.