Search code examples
react-nativegpsmobile-application

How we can get GPS location within a mobile app written in React Native


I have written a mobile app in React Native. I need to have user GPS location in some time steps. Does any one know what is the best library and method to get GPS location within a mobile app written in React Native? ( for both IOS and android )

Thanks


Solution

  • Try with react-native-geolocation

    Install it first:

    npm install @react-native-community/geolocation --save

    react-native link @react-native-community/geolocation

    Then, to request access to location, you need to add the following line to your app's AndroidManifest.xml

    Then use it on your app:

    import Geolocation from '@react-native-community/geolocation';
    
    Geolocation.getCurrentPosition(info => console.log(info));