userTrackingMode FollowWithCourse does not consider minDisplacement
See original GitHub issueWe are building an app for driving directions and navigation. We want to use userFollowMode = “course” to orient the map in the direction of the device’s movement.
This works fine when the device is in motion, for example when walking briskly or when in a vehicle driving. However when the device is stationary, the map spins due to extremely small GPS measurements each second.
The minDisplacement parameter is meant to limit GPS updates to a given threshold of movement. We have tested with various thresholds. It appears that minDisplacement works properly in limiting updates to coordinates.
However the FollowWithCourse mode seems to separately consider continuous GPS updates, causing the map orientation to spin when the device is near stationary, due to the noise in the GPS signal.
The FollowWithCourse mode should consider minDisplacement to limit updates to the Camera orientation, only adjusting the orientation with major GPS updates rather than continuous minor updates to prevent spinning.
Below is sample code where you can adjust the minDisplacement value with GPS update logs printed to the screen. The map will spin when the device is stationary, even with the minDisplacement is set at a higher value such as 10.
const MapScreen = ({}) => {
const [currentCoords, setCurrentCoords] = useState({})
const handleOnUpdate = (feature) => {
setCurrentCoords(feature)
}
return (
<SafeAreaView style={styles.container}>
<MapboxGL.MapView
style={styles.map}
tintColor={'red'}
compassEnabled={true}>
<MapboxGL.Camera followUserLocation={true} followUserMode={'course'} />
<MapboxGL.UserLocation
renderMode={'normal'}
showsUserHeadingIndicator={true}
androidRenderMode={'normal'}
minDisplacement={0}
onUpdate={handleOnUpdate}
/>
</MapboxGL.MapView>
<Text style={{ backgroundColor: 'gray' }}>
{JSON.stringify(currentCoords)}
</Text>
</SafeAreaView>
)
}
-Occurs on both Android and iOS platforms -react-native-mapbox-gl version: 8.1.0 -react-native version: 0.63.3
Issue Analytics
- State:
- Created 2 years ago
- Comments:12 (8 by maintainers)
Top GitHub Comments
We are running into this as well unfortunately but we only see it happening on Android.
We additionally use react-native-background-geolocation which could be overriding GPS update frequencies from Mapbox’s internal updates on iOS preventing the issue on iOS but having it happen on Android.
No Solution here, but just +1 this issue!
So I’ve identified that the LocationComponentManager.java attempts to separate the user location requests and the camera location request. This is where we can access the correct location component.
Docs: https://docs.mapbox.com/android/maps/api/9.6.0/com/mapbox/mapboxsdk/location/LocationComponent.html
TBD how to actually address the issue though.