skip to Main Content

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


  1. 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

    Login or Signup to reply.
  2. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search