question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

userTrackingMode FollowWithCourse does not consider minDisplacement

See original GitHub issue

We 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:closed
  • Created 2 years ago
  • Comments:12 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
dorthweincommented, Sep 22, 2021

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!

1reaction
dorthweincommented, Sep 29, 2021

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

userTrackingMode FollowWithCourse does not consider ...
The FollowWithCourse mode should consider minDisplacement to limit updates to the Camera orientation, only adjusting the orientation with major ...
Read more >
userTrackingMode | Apple Developer Documentation
A Boolean value that indicates whether the user's location is visible in the map view. var userLocation: MKUserLocation. The annotation object that represents ......
Read more >
Switch between user tracking modes | Maps SDK v6 - Mapbox
This example uses two classes within a single file: UserLocationButton is a subclass of UIButton that updates its style when the tracking mode...
Read more >
User Tracking Mode Missing Animation, Swift - Stack Overflow
You can call setUserTrackingMode:animated in order to animate the transition: @IBAction func UserTrackingMode(sender: AnyObject) { mapView.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found