how to use Mapbox.userlocation

750 Views Asked by At

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

There are 2 best solutions below

0
Kirill Novikov On BEST ANSWER

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

2
Akh On

The most supported way as part of React Native MapBox is UserLocation.onUpdate

<MapboxGL.MapView>
    <MapboxGL.UserLocation onUpdate={userLocationUpdate} />
</MapboxGL.MapView>

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.