maps: MapView's onUserLocationUpdate doesn't seem to fire
Describe the bug MapView’s onUserLocationUpdate doesn’t seem to fire.
To Reproduce
onUserLocationUpdate = (location) => {
console.log('location',location);
}
render() {
return (
<MapboxGL.MapView
animated
ref={c => this.map = c}
styleURL={this.props.theme.styleURL}
onUserLocationUpdate={this.onUserLocationUpdate}
onPress={this.onPress}
logoEnabled={false}
compassEnabled={false}
pitchEnabled={false}
onRegionWillChange={this.onRegionWillChange}
style={{ flex: 1 }}
onDidFinishLoadingMap={this.onDidFinishLoadingMap}
onDidFinishRenderingMap={this.onDidFinishRenderingMap}
onDidFinishRenderingMapFully={this.onDidFinishRenderingMapFully}
onDidFinishLoadingStyle={this.onDidFinishLoadingStyle}
onUserLocationUpdate={this.onUserLocationUpdate}
>
<MapboxGL.UserLocation visible={true} renderMode="custom">
<MapboxGL.CircleLayer id="mapboxUserLocationPluseCircle" style={layerStyles.normal.pulse} />
<MapboxGL.CircleLayer id="mapboxUserLocationWhiteCircle" style={layerStyles.normal.background} />
<MapboxGL.CircleLayer id="mapboxUserLocationBlueCicle" aboveLayerID="mapboxUserLocationWhiteCircle" style={layerStyles.normal.foreground} />
</MapboxGL.UserLocation>
<MapboxGL.Camera
followUserLocation={this.state.currentTrackingModeIsFollowing}
followUserMode="course"
onUserTrackingModeChange={this.onUserTrackingModeChange}
/>
</MapboxGL.MapView>
)
}
Expected behavior Expected onUserLocationUpdate to fire the callback
Screenshots N/A
Versions (please complete the following information):
- Platfrom: iOS
- Device: iPhone 7 Plus
- OS: iOS 12.3.1.
- SDK Version: N/A
- react-native-mapbox-gl Version: 7.0.0-rc3
- React Native Version 0.56.0
Additional context Just doesn’t seem to fire. I searched the repo’s source code and not sure why it could be not working - seems like onUserLocationUpdate is still a prop of MapView, not Camera. Not quite sure if it’s because of some props i’m passing in. Was working fine 6.1.2
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 3
- Comments: 26 (18 by maintainers)
We should create a throttle control for this and onRegionIsChanging similar to ScrollView onScroll. The throttle should happen on native side to prevent unnecessary bridge activity.
Happy to see a PR for this. The RN core ScrollView can be a good source of inspiration for this code.
On Wed, 30 Oct 2019 at 19:39, Richard Lindhout notifications@github.com wrote:
Interestingly I’ve noticed, that it not always fires like crazy, sometimes it’s less frequent, sometimes more… I also only monitor it via remote debugger when in the office.
You should log it, it’s extreme how much update
My HOC component (I have a shared codebase with react-native-web)
@ferdicus you have to debounce this onUpdate since it fires at least every second and without any movement.
It not there I think
I use the UserLocation
With that on update you need to check if the distance between the old and the new point is greater than … or else you have an update every second.