I am trying to use mapbox in react native and i want the location of the user. the function mapbox.userlocation can be used with the mapbox.mapview. but i would like to use the location in some other way too.
Any suggestions?
I am trying to use mapbox in react native and i want the location of the user. the function mapbox.userlocation can be used with the mapbox.mapview. but i would like to use the location in some other way too.
Any suggestions?
2
Answers
MapBox provides you with UI components. One of the possible ways is to use the function
onUserLocationUpdate
from https://github.com/rnmapbox/maps/blob/main/docs/MapView.md.However better approach is to use the right library for it, for example https://github.com/michalchudziak/react-native-geolocation
The most supported way as part of React Native MapBox is UserLocation.onUpdate
The only limitation of this approach is that you may need to perform debouncing, as the callback may be fired even when the location has not changed or has changed only very little.