├── .eslintignore ├── .eslintrc.js ├── .gitattributes ├── .github ├── FUNDING.yml ├── ISSUE_TEMPLATE │ └── start-a-new-issue.md └── workflows │ └── github-dependents-info.yml ├── .gitignore ├── .npmignore ├── .prettierrc.js ├── DEPENDENTS.md ├── LICENSE ├── README.md ├── ReactNativeGetLocation.podspec ├── Sample ├── .eslintrc.js ├── .gitignore ├── .node-version ├── .prettierrc.js ├── .watchmanconfig ├── App.tsx ├── __tests__ │ └── App-test.tsx ├── android │ ├── app │ │ ├── build.gradle │ │ ├── debug.keystore │ │ ├── proguard-rules.pro │ │ └── src │ │ │ ├── debug │ │ │ ├── AndroidManifest.xml │ │ │ └── java │ │ │ │ └── com │ │ │ │ └── reactnativegetlocationsample │ │ │ │ └── ReactNativeFlipper.java │ │ │ ├── main │ │ │ ├── AndroidManifest.xml │ │ │ ├── java │ │ │ │ └── com │ │ │ │ │ └── reactnativegetlocationsample │ │ │ │ │ ├── MainActivity.java │ │ │ │ │ └── MainApplication.java │ │ │ └── res │ │ │ │ ├── drawable │ │ │ │ └── rn_edit_text_material.xml │ │ │ │ ├── mipmap-hdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ │ ├── mipmap-mdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ │ ├── mipmap-xhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ │ ├── mipmap-xxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ │ ├── mipmap-xxxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ │ └── values │ │ │ │ ├── strings.xml │ │ │ │ └── styles.xml │ │ │ └── release │ │ │ └── java │ │ │ └── com │ │ │ └── reactnativegetlocationsample │ │ │ └── ReactNativeFlipper.java │ ├── build.gradle │ ├── gradle.properties │ ├── gradle │ │ └── wrapper │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ ├── gradlew │ ├── gradlew.bat │ └── settings.gradle ├── app.json ├── babel.config.js ├── index.js ├── install.sh ├── ios │ ├── .xcode.env │ ├── Podfile │ ├── Podfile.lock │ ├── ReactNativeGetLocationSample.xcodeproj │ │ ├── project.pbxproj │ │ └── xcshareddata │ │ │ └── xcschemes │ │ │ └── ReactNativeGetLocationSample.xcscheme │ ├── ReactNativeGetLocationSample.xcworkspace │ │ ├── contents.xcworkspacedata │ │ └── xcshareddata │ │ │ └── IDEWorkspaceChecks.plist │ ├── ReactNativeGetLocationSample │ │ ├── AppDelegate.h │ │ ├── AppDelegate.mm │ │ ├── Images.xcassets │ │ │ ├── AppIcon.appiconset │ │ │ │ └── Contents.json │ │ │ └── Contents.json │ │ ├── Info.plist │ │ ├── LaunchScreen.storyboard │ │ └── main.m │ └── ReactNativeGetLocationSampleTests │ │ ├── Info.plist │ │ └── ReactNativeGetLocationSampleTests.m ├── metro.config.js ├── package.json ├── pod-install.sh ├── tsconfig.json └── yarn.lock ├── android ├── build.gradle └── src │ └── main │ ├── AndroidManifest.xml │ └── java │ └── com │ └── github │ └── douglasjunior │ └── reactNativeGetLocation │ ├── ReactNativeGetLocationPackage.java │ ├── modules │ └── ReactNativeGetLocationModule.java │ └── util │ ├── GetLocation.java │ └── SettingsUtil.java ├── babel.config.js ├── ios ├── ReactNativeGetLocation.xcodeproj │ ├── project.pbxproj │ └── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ └── xcshareddata │ │ └── IDEWorkspaceChecks.plist └── ReactNativeGetLocationLibrary │ ├── LocationModule.h │ ├── LocationModule.m │ ├── SettingsUtil.h │ └── SettingsUtil.m ├── package.json ├── scripts └── publish.js ├── src ├── LocationError.ts ├── index.ts └── utils.ts ├── tsconfig.json └── yarn.lock /.eslintignore: -------------------------------------------------------------------------------- 1 | /dist 2 | /node_modules 3 | -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | root: true, 3 | extends: '@react-native-community', 4 | }; 5 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | *.pbxproj -text 2 | Sample/** linguist-vendored 3 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: douglasjunior 4 | patreon: douglasjunior # Replace with a single Patreon username 5 | # open_collective: rn-keyboard-manager # Replace with a single Open Collective username 6 | custom: paypal.me/douglasnassif 7 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/start-a-new-issue.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Start a new issue 3 | about: Create a new issue to report a bug, feature or suggestion requests. 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | 13 | 14 | - How did you link to the library (autolinking, manual, rn link, cocoapods)? 15 | - What version of React Native? 16 | - What version of the library? 17 | - iOS/Android version? 18 | - Did the problem happen after updating React Native? 19 | - Are you using the library for the first time? 20 | - It's a bug? Provide a link to a minimal reproduction case. 21 | -------------------------------------------------------------------------------- /.github/workflows/github-dependents-info.yml: -------------------------------------------------------------------------------- 1 | # GitHub Dependents Info workflow 2 | # More info at https://github.com/nvuillam/github-dependents-info/ 3 | name: GitHub Dependents Info 4 | 5 | # Let by default 6 | on: 7 | # On manual launch 8 | workflow_dispatch: 9 | # On every push on selected branches (usually just main) 10 | # push: 11 | # branches: [main] 12 | # Scheduled interval: Use CRON format https://crontab.guru/ 13 | schedule: 14 | - cron: "0 0 * * 6" # Every sunday at midnight 15 | 16 | permissions: read-all 17 | 18 | concurrency: 19 | group: ${{ github.ref }}-${{ github.workflow }} 20 | cancel-in-progress: true 21 | 22 | jobs: 23 | build: 24 | name: GitHub Dependents Info 25 | runs-on: ubuntu-latest 26 | permissions: 27 | contents: write 28 | pull-requests: write 29 | steps: 30 | # Git Checkout 31 | - name: Checkout Code 32 | uses: actions/checkout@v4 33 | with: 34 | token: ${{ secrets.PAT || secrets.GITHUB_TOKEN }} 35 | fetch-depth: 0 36 | 37 | # Collect data & generate markdown 38 | - name: GitHub Dependents Info 39 | uses: nvuillam/github-dependents-info@v1.5.1 # If you trust me enough you can replace version by "main" :) 40 | # See documentation for variables details: https://github.com/nvuillam/github-dependents-info?tab=readme-ov-file#%EF%B8%8F-usage 41 | with: 42 | repo: ${{ github.repository }} 43 | outputrepo: ${{ github.repository }} 44 | markdownfile: ./DEPENDENTS.md 45 | # badgemarkdownfile: README.md 46 | sort: stars 47 | # minstars: "0" 48 | env: 49 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 50 | 51 | # Workaround for git issues 52 | - name: Prepare commit 53 | run: sudo chown -R $USER:$USER . 54 | 55 | # Create pull request 56 | - name: Create Pull Request 57 | id: cpr 58 | uses: peter-evans/create-pull-request@v6 59 | with: 60 | token: ${{ secrets.PAT || secrets.GITHUB_TOKEN }} 61 | branch: github-dependents-info-auto-update 62 | commit-message: "[GitHub Dependents Info] Updated markdown file(s)" 63 | delete-branch: true 64 | title: "[GitHub Dependents Info] Updated markdown file" 65 | body: "_Generated with [github-dependents-info](https://github.com/nvuillam/github-dependents-info), by [Nicolas Vuillamy](https://github.com/nvuillam)_" 66 | labels: documentation 67 | - name: Create PR output 68 | run: | 69 | echo "Pull Request Number - ${{ steps.cpr.outputs.pull-request-number }}" 70 | echo "Pull Request URL - ${{ steps.cpr.outputs.pull-request-url }}" 71 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # OSX 2 | # 3 | .DS_Store 4 | 5 | # Xcode 6 | # 7 | build/ 8 | *.pbxuser 9 | !default.pbxuser 10 | *.mode1v3 11 | !default.mode1v3 12 | *.mode2v3 13 | !default.mode2v3 14 | *.perspectivev3 15 | !default.perspectivev3 16 | xcuserdata 17 | *.xccheckout 18 | *.moved-aside 19 | DerivedData 20 | *.hmap 21 | *.ipa 22 | *.xcuserstate 23 | ios/.xcode.env.local 24 | 25 | # Android/IntelliJ 26 | # 27 | build/ 28 | .idea 29 | .gradle 30 | local.properties 31 | *.iml 32 | *.hprof 33 | .cxx/ 34 | *.keystore 35 | !debug.keystore 36 | 37 | # node.js 38 | # 39 | node_modules/ 40 | npm-debug.log 41 | yarn-error.log 42 | 43 | # fastlane 44 | # 45 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 46 | # screenshots whenever they are needed. 47 | # For more information about the recommended setup visit: 48 | # https://docs.fastlane.tools/best-practices/source-control/ 49 | 50 | **/fastlane/report.xml 51 | **/fastlane/Preview.html 52 | **/fastlane/screenshots 53 | **/fastlane/test_output 54 | 55 | # Bundle artifact 56 | *.jsbundle 57 | 58 | # Ruby / CocoaPods 59 | /ios/Pods/ 60 | /vendor/bundle/ 61 | 62 | # Temporary files created by Metro to check the health of the file watcher 63 | .metro-health-check* 64 | 65 | /dist 66 | !/dist/.gitkeep 67 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | .vscode/ 2 | .github/ 3 | .prettierrc.js 4 | .eslintrc.js 5 | yarn.lock 6 | tsconfig.json 7 | babel.config.js 8 | node_modules/ 9 | __tests__/ 10 | screenshots/ 11 | Sample/ 12 | src/ 13 | scripts/ 14 | -------------------------------------------------------------------------------- /.prettierrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | arrowParens: 'avoid', 3 | bracketSameLine: true, 4 | bracketSpacing: false, 5 | singleQuote: true, 6 | trailingComma: 'all', 7 | }; 8 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Douglas Nassif Roma Junior 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # React-Native Get Location 2 | 3 | [![License MIT](https://img.shields.io/badge/licence-MIT-blue.svg)](https://github.com/douglasjunior/react-native-get-location/blob/master/LICENSE) 4 | [![npm version](https://img.shields.io/npm/v/react-native-get-location.svg)](https://www.npmjs.com/package/react-native-get-location) 5 | [![npm downloads](https://img.shields.io/npm/dt/react-native-get-location.svg)](https://www.npmjs.com/package/react-native-get-location?activeTab=versions) 6 | 7 | ⚛ Simple to use React Native library to get native device location for Android and iOS. 8 | 9 | ## Requirements 10 | 11 | - React Native >= 0.60.0 12 | - iOS >= 9.0 13 | 14 | ## Install 15 | 16 | Install dependency package 17 | ```bash 18 | yarn add react-native-get-location 19 | ``` 20 | Or 21 | ```bash 22 | npm i -S react-native-get-location 23 | ``` 24 | 25 | Go to the folder **your-project/ios** and run `pod install`, and you're done. 26 | 27 | ## Android post install 28 | 29 | For Android you need to define the location permissions on `AndroidManifest.xml`. 30 | 31 | ```xml 32 | 33 | 34 | 35 | 36 | 37 | ``` 38 | 39 | ## iOS post install 40 | 41 | You need to define the permission [NSLocationWhenInUseUsageDescription](https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CocoaKeys.html#//apple_ref/doc/uid/TP40009251-SW26) on `Info.plist`. 42 | 43 | ```xml 44 | NSLocationWhenInUseUsageDescription 45 | This app needs to get your location... 46 | ``` 47 | 48 | ## Usage 49 | 50 | There is only one function that you need to use to get the user's current location. 51 | 52 | ```js 53 | import GetLocation from 'react-native-get-location' 54 | 55 | GetLocation.getCurrentPosition({ 56 | enableHighAccuracy: true, 57 | timeout: 60000, 58 | }) 59 | .then(location => { 60 | console.log(location); 61 | }) 62 | .catch(error => { 63 | const { code, message } = error; 64 | console.warn(code, message); 65 | }) 66 | ``` 67 | 68 | For more details, see the [Sample Project](https://github.com/douglasjunior/react-native-get-location/blob/master/Sample/App.tsx). 69 | 70 | ## API 71 | 72 | ### function `GetLocation.getCurrentPosition(LocationConfig)` 73 | 74 | **Parameters:** 75 | - [`LocationConfig`](#object-locationconfig): Configuration object to determine how to get the user current location. 76 | 77 | **Return:** 78 | - `Promise<`[`Location`](#object-location)`>`: Promise thats resolve to a Location object. 79 | 80 | ### Object `LocationConfig` 81 | 82 | **Properties:** 83 | - `enableHighAccuracy`: Set `true` to use 'fine location' (GPS) our `false` to use 'course location' (Wifi, Bluetooth, 3G). Default: `false` 84 | - `timeout`: The max time (in milliseconds) that you want to wait to receive a location. Default: `60000` (60 seconds) 85 | - `rationale?`: (Android only) See the [React Native docs](https://reactnative.dev/docs/permissionsandroid#request). 86 | 87 | ### Object `Location` 88 | 89 | **Properties:** 90 | - `latitude`: The latitude, in degrees. 91 | - `longitude`: The longitude, in degrees. 92 | - `altitude`: The altitude if available, in meters above the WGS 84 reference ellipsoid. 93 | - `accuracy`: The estimated horizontal accuracy of this location, radial, in meters. 94 | - `speed`: The speed if it is available, in meters/second over ground. 95 | - `time`: The UTC time of this fix, in milliseconds since January 1, 1970. 96 | - `bearing`: *(Android only)* The bearing, in degrees. 97 | - `provider`: *(Android only)* The name of the provider that generated this fix. 98 | - `verticalAccuracy`: *(iOS only)* The vertical accuracy of the location. Negative if the altitude is invalid. 99 | - `course`: *(iOS only)* The course of the location in degrees true North. Negative if course is invalid. (0.0 - 359.9 degrees, 0 being true North) 100 | 101 | ### Error codes 102 | 103 | |Code|Message| 104 | |-|-| 105 | |`CANCELLED`|Location cancelled by user or by another request| 106 | |`UNAVAILABLE`|Location service is disabled or unavailable| 107 | |`TIMEOUT`|Location request timed out| 108 | |`UNAUTHORIZED`|Authorization denied| 109 | 110 | ## Contribute 111 | 112 | New features, bug fixes and improvements are welcome! For questions and suggestions use the [issues](https://github.com/douglasjunior/react-native-get-location/issues). 113 | 114 | Become a Patron! 115 | [![Donate](https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif)](https://paypal.me/douglasnassif) 116 | 117 | ## Star History 118 | 119 | [![Star History Chart](https://api.star-history.com/svg?repos=douglasjunior/react-native-get-location&type=Date)](https://star-history.com/#douglasjunior/react-native-get-location) 120 | 121 | ## License 122 | 123 | ``` 124 | The MIT License (MIT) 125 | 126 | Copyright (c) 2019 Douglas Nassif Roma Junior 127 | ``` 128 | 129 | See the full [license file](https://github.com/douglasjunior/react-native-get-location/blob/master/LICENSE). 130 | -------------------------------------------------------------------------------- /ReactNativeGetLocation.podspec: -------------------------------------------------------------------------------- 1 | require 'json' 2 | 3 | packageJson = JSON.parse(File.read('package.json')) 4 | version = packageJson["version"] 5 | repository = packageJson["repository"]["url"] 6 | 7 | Pod::Spec.new do |s| 8 | s.name = "ReactNativeGetLocation" 9 | s.version = version 10 | s.description = packageJson["description"] 11 | s.homepage = packageJson["homepage"] 12 | s.summary = packageJson["description"] 13 | s.license = packageJson["license"] 14 | s.authors = packageJson["author"] 15 | s.source = { :git => repository, :tag => version } 16 | s.platform = :ios, "9.0" 17 | s.preserve_paths = 'README.md', 'package.json', '*.js' 18 | s.source_files = 'ios/ReactNativeGetLocationLibrary/**/*.{h,m}' 19 | 20 | s.dependency 'React-Core' 21 | end 22 | -------------------------------------------------------------------------------- /Sample/.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | root: true, 3 | extends: '@react-native-community', 4 | }; 5 | -------------------------------------------------------------------------------- /Sample/.gitignore: -------------------------------------------------------------------------------- 1 | # OSX 2 | # 3 | .DS_Store 4 | 5 | # Xcode 6 | # 7 | build/ 8 | *.pbxuser 9 | !default.pbxuser 10 | *.mode1v3 11 | !default.mode1v3 12 | *.mode2v3 13 | !default.mode2v3 14 | *.perspectivev3 15 | !default.perspectivev3 16 | xcuserdata 17 | *.xccheckout 18 | *.moved-aside 19 | DerivedData 20 | *.hmap 21 | *.ipa 22 | *.xcuserstate 23 | ios/.xcode.env.local 24 | 25 | # Android/IntelliJ 26 | # 27 | build/ 28 | .idea 29 | .gradle 30 | local.properties 31 | *.iml 32 | *.hprof 33 | .cxx/ 34 | *.keystore 35 | !debug.keystore 36 | 37 | # node.js 38 | # 39 | node_modules/ 40 | npm-debug.log 41 | yarn-error.log 42 | 43 | # fastlane 44 | # 45 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 46 | # screenshots whenever they are needed. 47 | # For more information about the recommended setup visit: 48 | # https://docs.fastlane.tools/best-practices/source-control/ 49 | 50 | **/fastlane/report.xml 51 | **/fastlane/Preview.html 52 | **/fastlane/screenshots 53 | **/fastlane/test_output 54 | 55 | # Bundle artifact 56 | *.jsbundle 57 | 58 | # Ruby / CocoaPods 59 | /ios/Pods/ 60 | /vendor/bundle/ 61 | 62 | # Temporary files created by Metro to check the health of the file watcher 63 | .metro-health-check* 64 | -------------------------------------------------------------------------------- /Sample/.node-version: -------------------------------------------------------------------------------- 1 | 18 2 | -------------------------------------------------------------------------------- /Sample/.prettierrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | arrowParens: 'avoid', 3 | bracketSameLine: true, 4 | bracketSpacing: false, 5 | singleQuote: true, 6 | trailingComma: 'all', 7 | }; 8 | -------------------------------------------------------------------------------- /Sample/.watchmanconfig: -------------------------------------------------------------------------------- 1 | {} -------------------------------------------------------------------------------- /Sample/App.tsx: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 Douglas Nassif Roma Junior 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | import React, {useState} from 'react'; 26 | import { 27 | Platform, 28 | StyleSheet, 29 | Text, 30 | View, 31 | Button, 32 | ActivityIndicator, 33 | } from 'react-native'; 34 | 35 | import GetLocation, { 36 | Location, 37 | LocationErrorCode, 38 | isLocationError, 39 | } from 'react-native-get-location'; 40 | 41 | const instructions = Platform.select({ 42 | ios: 'Press Cmd+R to reload,\n' + 'Cmd+D or shake for dev menu', 43 | android: 44 | 'Double tap R on your keyboard to reload,\n' + 45 | 'Shake or press menu button for dev menu', 46 | }); 47 | 48 | const styles = StyleSheet.create({ 49 | container: { 50 | flex: 1, 51 | justifyContent: 'center', 52 | alignItems: 'center', 53 | backgroundColor: '#F5FCFF', 54 | }, 55 | welcome: { 56 | fontSize: 20, 57 | textAlign: 'center', 58 | margin: 10, 59 | }, 60 | instructions: { 61 | textAlign: 'center', 62 | color: '#333333', 63 | marginBottom: 5, 64 | }, 65 | location: { 66 | color: '#333333', 67 | marginBottom: 5, 68 | }, 69 | button: { 70 | marginBottom: 8, 71 | }, 72 | }); 73 | 74 | function App(): JSX.Element { 75 | const [loading, setLoading] = useState(false); 76 | const [location, setLocation] = useState(null); 77 | const [error, setError] = useState(null); 78 | 79 | const requestLocation = () => { 80 | setLoading(true); 81 | setLocation(null); 82 | setError(null); 83 | 84 | GetLocation.getCurrentPosition({ 85 | enableHighAccuracy: true, 86 | timeout: 30000, 87 | rationale: { 88 | title: 'Location permission', 89 | message: 'The app needs the permission to request your location.', 90 | buttonPositive: 'Ok', 91 | }, 92 | }) 93 | .then(newLocation => { 94 | setLoading(false); 95 | setLocation(newLocation); 96 | }) 97 | .catch(ex => { 98 | if (isLocationError(ex)) { 99 | const {code, message} = ex; 100 | console.warn(code, message); 101 | setError(code); 102 | } else { 103 | console.warn(ex); 104 | } 105 | setLoading(false); 106 | setLocation(null); 107 | }); 108 | }; 109 | 110 | return ( 111 | 112 | Welcome to React Native! 113 | 114 | To get location, press the button: 115 | 116 | 117 | 118 |