UserLocation minDisplacement not limiting calls for onUpdate
See original GitHub issueDescription of the issue/bug
UserLocation.minDisplacement
does not seem to limit the number of calls on UserLocation.onUpdate
.
There is currently no documentation available, but I assume that the purpose of the property minDisplacement
is to set the minimum distance (meters?) a user’s location has to change before UserLocation
will receive an update.
Setting minDisplacement
to high values did not make any difference though. UserLocation.onUpdate
was called by rotating my phone without moving anywhere.
import React from 'react';
import {
MapView,
ShapeSource,
LineLayer,
Camera,
UserLocation,
} from '@react-native-mapbox-gl/maps';
const aLine = {
type: 'LineString',
coordinates: [
[-74.00597, 40.71427],
[-74.00697, 40.71527],
],
};
class BugReportExample extends React.Component {
onUpdatePosition(location) {
console.log('Updated position')
// minDisplacement on UserLocation doesn't seem to limit the
// call for onUpdate.
this.setState({ location: location });
}
render() {
return (
<MapView style={{flex: 1}}>
<Camera centerCoordinate={[-74.00597, 40.71427]} zoomLevel={14} />
<ShapeSource id="idStreetLayer" shape={aLine}>
<LineLayer id="idStreetLayer" />
</ShapeSource>
<UserLocation
visible={true}
renderMode={'normal'}
minDisplacement={5}
onUpdate={(location) => this.onUpdatePosition(location)}
showsUserHeadingIndicator={true} />
</MapView>
);
}
}
This might also be related to issue #770
I might just misunderstand the purpose of minDisplacement
. If so then this would be a great feature to have.
Versions:
- Platform: iOS
- Device: iPhone11
- Emulator/ Simulator: no
- OS: 13.4.1
- react-native-mapbox-gl Version 8.0.0
- React Native Version 0.62.2
Issue Analytics
- State:
- Created 3 years ago
- Comments:17 (14 by maintainers)
Top Results From Across the Web
UserLocation minDisplacement not limiting calls for onUpdate
Description of the issue/bug UserLocation.minDisplacement does not seem to limit the number of calls on UserLocation.onUpdate.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi @ferdicus. Just tested the branch and
onUpdate
gets now called as expected, i.e. whenminDisplacement
is reached. Thanks for taking care of this!I just wanted to note that when
showsUserHeadingIndicator={true}
is set, the indicator arrow is also affected. It only updates along withminDisplacement
. I assume it’s not possible with this fix to keep theonUpdate
callback independent from the heading indicator updates. I just think that most use cases want to see the heading indicator continuously updating and see the displacement updates only in terms of ‘moving a certain distance on the ground’. Maybe the only solution for this case is to keep the displacement at 0 and limit any state updates inside theonUpdate
callback instead.At least there is now a choice since before the
minDisplacement
value didn’t have any effect on iOS. Thanks 😃The userLocation expects heading for displaying direction. Maybe we can skip calling delegate when minDisplacement is set.