{"id":8647,"date":"2024-03-01T13:07:56","date_gmt":"2024-03-01T13:07:56","guid":{"rendered":"https:\/\/dianapps.com\/blog\/?p=8647"},"modified":"2024-04-17T11:38:52","modified_gmt":"2024-04-17T11:38:52","slug":"how-to-use-react-native-geolocation-service","status":"publish","type":"post","link":"https:\/\/dianapps.com\/blog\/how-to-use-react-native-geolocation-service\/","title":{"rendered":"How to use React Native Geolocation Service?"},"content":{"rendered":"<p><span style=\"font-weight: 400;\">You may have questioned how ride-hailing and food delivery services determine your current location. Ever come across the term Geolocation?<\/span><\/p>\n<p><span style=\"font-weight: 400;\">We&#8217;ll learn how to use geolocation in React Native in this tutorial. We&#8217;ll create an example application that allows the user to submit their position to another source, such as<\/span><a href=\"https:\/\/dianapps.com\/blog\/building-a-twitter-clone-app-in-react-native\/\"><span style=\"font-weight: 400;\"> Twitter<\/span><\/a><span style=\"font-weight: 400;\">, and shows their location on a map with longitude and latitude data.<\/span><\/p>\n<h1><span class=\"ez-toc-section\" id=\"What-is-geolocation\"><\/span><span style=\"font-weight: 400;\">What is geolocation?<\/span><span class=\"ez-toc-section-end\"><\/span><\/h1>\n<p><span style=\"font-weight: 400;\">The ability to determine a device&#8217;s geographic location to the internet is known as geolocation. Using a device&#8217;s IP address to find its location in terms of nation, city, or postal code is a basic example of geolocation. Most of the time, an app cannot access a user&#8217;s location data without the user&#8217;s consent.<\/span><\/p>\n<h2><span class=\"ez-toc-section\" id=\"Geolocation-in-React-Native\"><\/span><span style=\"font-weight: 400;\">Geolocation in React Native<\/span><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><img decoding=\"async\" class=\"wp-image-8652 size-full aligncenter\" src=\"https:\/\/dianapps.com\/blog\/wp-content\/uploads\/2024\/03\/image7.png\" alt=\"\" width=\"868\" height=\"801\" srcset=\"https:\/\/dianapps.com\/blog\/wp-content\/uploads\/2024\/03\/image7.png 868w, https:\/\/dianapps.com\/blog\/wp-content\/uploads\/2024\/03\/image7-768x709.png 768w, https:\/\/dianapps.com\/blog\/wp-content\/uploads\/2024\/03\/image7-640x591.png 640w, https:\/\/dianapps.com\/blog\/wp-content\/uploads\/2024\/03\/image7-400x369.png 400w\" sizes=\"(max-width: 868px) 100vw, 868px\" \/><\/p>\n<p><span style=\"font-weight: 400;\">The <\/span><a href=\"https:\/\/github.com\/react-native-geolocation\/react-native-geolocation\"><span style=\"font-weight: 400;\">@react-native-community\/geolocation<\/span><\/a><span style=\"font-weight: 400;\"> API for geolocation is made available by React Native. However, because the React Native API is slower and less precise than the suggested Google Location Services API, <\/span><a href=\"https:\/\/developers.google.com\/maps\/documentation\/geolocation\/overview\"><span style=\"font-weight: 400;\">Google<\/span><\/a><span style=\"font-weight: 400;\"> does not advise using it for geolocation.<\/span><\/p>\n<p>React Native <span style=\"font-weight: 400;\">geolocation services can now be easily implemented in React Native thanks to the <\/span><a href=\"https:\/\/reactnative.directory\/?search=geolocation\"><span style=\"font-weight: 400;\">wonderful libraries<\/span><\/a><span style=\"font-weight: 400;\"> created by the React Native community, such as<\/span><a href=\"https:\/\/www.npmjs.com\/package\/react-native-location\"><span style=\"font-weight: 400;\"> react-native-location<\/span><\/a><span style=\"font-weight: 400;\"> and <\/span><a href=\"https:\/\/www.npmjs.com\/package\/react-native-geolocation-service\"><span style=\"font-weight: 400;\">react-native-geolocation-service<\/span><\/a><span style=\"font-weight: 400;\">.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">We&#8217;ll be using the react-native-geolocation-service library in this React Native geolocation tutorial; it&#8217;s accessible as a Node package on <\/span><a href=\"https:\/\/www.npmjs.com\/package\/react-native-geolocation-service\"><span style=\"font-weight: 400;\">npm<\/span><\/a><span style=\"font-weight: 400;\">.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Our program will be able to perform the following tasks:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Requests authorization to access location information on your iOS and Android smartphone.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Select the coordinates of your location.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Retains or transmits your position data<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">Execute the following code to find out your Node.js version:<\/span><\/p>\n<p><b>$ node -v<\/b><\/p>\n<p><b>\/\/ returns node version<\/b><\/p>\n<p><span style=\"font-weight: 400;\">Multiple Node.js versions installed on your computer may be managed with nvm. You may create a new project using the integrated command line interface of React Native app development framework. It may be accessed with npx, which comes with Node.js, without requiring any global installations.<\/span><\/p>\n<h2><span class=\"ez-toc-section\" id=\"Initialize-a-React-Native-project\"><\/span><span style=\"font-weight: 400;\">Initialize a React Native project<\/span><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-weight: 400;\">Enter the following command into your terminal to get started:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">$ npx ReactNativeGeolocation init <\/span><b>React Native app development.\u00a0<\/b><\/p>\n<p><span style=\"font-weight: 400;\">You may execute Node-based dependencies in your terminal without installing them on your computer by using the Node-based command npx.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">The directive to create a new React Native project using ReactNativeLocation as the location where the project files will be installed is contained in the init portion of the command.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">It is not necessary to install React Native development services on your computer in order to use the npx react-native command. As an alternative, you may use npx to execute React Native instructions by installing React Native globally on your computer. Use this command to install React Native globally:<\/span><\/p>\n<p><b>$ npm install -g react-native-cli<\/b><\/p>\n<p><span style=\"font-weight: 400;\">Next, you can use the following command to verify that React Native is installed:<\/span><\/p>\n<p><strong>$react-native -v<\/strong><\/p>\n<p><span style=\"font-weight: 400;\">The aforementioned program outputs to the console the installed version of React Native on your system. Navigate to the ReactNativeGeolocation directory using your preferred IDE.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">The<\/span><a href=\"https:\/\/dianapps.com\/blog\/10-reasons-to-choose-react-native-app-development\/\"><span style=\"font-weight: 400;\"> React Native app<\/span><\/a><span style=\"font-weight: 400;\"> has been configured for us by the command we performed to begin the project.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">All of our code will be written in the App.js file. To execute the instructions, make sure you are in your application&#8217;s root directory.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Launching<\/span><a href=\"https:\/\/facebook.github.io\/metro\/docs\/concepts\/\"><span style=\"font-weight: 400;\"> Metro<\/span><\/a><span style=\"font-weight: 400;\"> is the first step. React Native comes with a JavaScript bundler called Metro. Metro generates a single JavaScript file with all of your code and its dependencies after receiving an entry file and several options:<\/span><\/p>\n<p><b>$ npx react-native start<\/b><\/p>\n<h4><span class=\"ez-toc-section\" id=\"Open-a-new-terminal-and-type-the-following-command-while-Metro-is-running-in-your-current-terminal\"><\/span><span style=\"font-weight: 400;\">Open a new terminal and type the following command while Metro is running in your current terminal:<\/span><span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p><span style=\"font-weight: 400;\">$npx run-android react-native<\/span><\/p>\n<p><span style=\"font-weight: 400;\">You&#8217;ll need an <\/span><a href=\"https:\/\/developer.android.com\/studio\/run\/managing-avds\"><span style=\"font-weight: 400;\">Android emulator<\/span><\/a><span style=\"font-weight: 400;\"> or a mobile device in debug mode connected to your PC to launch the app. However, the following causes might cause an error if you&#8217;re using the emulator in Android Studio:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">An ANDROID_HOME environment variable that links to the SDK directory must be defined.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">You must accept every<\/span><a href=\"https:\/\/developer.android.com\/studio\/intro\/update\"><span style=\"font-weight: 400;\"> SDK license<\/span><\/a><span style=\"font-weight: 400;\">.<\/span><\/p>\n<h4><span class=\"ez-toc-section\" id=\"The-screen-that-appears-next-should-be-as-follows\"><\/span><span style=\"font-weight: 400;\">The screen that appears next should be as follows:<\/span><span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p><img decoding=\"async\" class=\"wp-image-8653 aligncenter\" src=\"https:\/\/dianapps.com\/blog\/wp-content\/uploads\/2024\/03\/image4.png\" alt=\"\" width=\"347\" height=\"618\" \/><\/p>\n<p><span style=\"font-weight: 400;\">We are now able to modify the application within our App.js folder. Take out all of the outdated code from App.js and replace it with this:<\/span><\/p>\n<pre class=\"theme:github font-size:14 nums:false lang:default decode:true\">\/**\r\n\r\n* Sample React Native App\r\n\r\n* https:\/\/github.com\/facebook\/react-native\r\n\r\n*\r\n\r\n* @format\r\n\r\n* @flow strict-local\r\n\r\n*\/\r\n\r\nimport React from 'react';\r\n\r\nimport {StyleSheet, View, Text} from 'react-native';\r\n\r\nconst App = () =&gt; {\r\n\r\n\u00a0return (\r\n\r\n\u00a0\u00a0\u00a0&lt;View style={styles.container}&gt;\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0&lt;Text&gt;Welcome!&lt;\/Text&gt;\r\n\r\n\u00a0\u00a0\u00a0&lt;\/View&gt;\r\n\r\n\u00a0);\r\n\r\n};\r\n\r\nconst styles = StyleSheet.create({\r\n\r\n\u00a0container: {\r\n\r\n\u00a0\u00a0\u00a0flex: 1,\r\n\r\n\u00a0\u00a0\u00a0backgroundColor: '#fff',\r\n\r\n\u00a0\u00a0\u00a0alignItems: 'center',\r\n\r\n\u00a0\u00a0\u00a0justifyContent: 'center',\r\n\r\n\u00a0},\r\n\r\n});\r\n\r\nexport default App;<\/pre>\n<p><span style=\"font-weight: 400;\">The code above opens a new window for us to write our application on:<\/span><\/p>\n<p><img decoding=\"async\" class=\"wp-image-8654 aligncenter\" src=\"https:\/\/dianapps.com\/blog\/wp-content\/uploads\/2024\/03\/image1.png\" alt=\"\" width=\"286\" height=\"569\" \/><\/p>\n<h2><span class=\"ez-toc-section\" id=\"React-Native-requirements-needed-for-geolocation\"><\/span><span style=\"font-weight: 400;\">React Native requirements needed for geolocation<\/span><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-weight: 400;\">Using Yarn or npm, install the react-native-geolocation-service library using the corresponding commands below:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">React-native-geolocation-service is added with yarn.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">React-native-geolocation-service &#8211;save may be installed with npm.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Previously, linking the library was required; however, in more recent iterations of <\/span><a href=\"https:\/\/dianapps.com\/react-native-app-development\"><b>React Native app development services<\/b><\/a><span style=\"font-weight: 400;\">, this process is automated when executing a build using npx react-native run-android, or its iOS counterpart.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0These connecting instructions should assist you in setting up React Native \u2264v0.60.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">In addition, we want to confirm that we include the following code to android\/src\/main\/AndroidManifest.xml to allow permissions in the application:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Android:name=&#8221;android.permission.INTERNET&#8221; \/&gt;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Run npx react-native run-android once more after that.<\/span><\/p>\n<h3><span class=\"ez-toc-section\" id=\"React-Native-application-geolocation-integration\"><\/span><span style=\"font-weight: 400;\">React Native application geolocation integration<\/span><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p><span style=\"font-weight: 400;\">Let&#8217;s add two buttons to our React Native app: one to communicate the user&#8217;s location to Twitter and another to get the user&#8217;s location, which we&#8217;ll keep in the app state.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Update the React Native imports to include Button, for example, import {StyleSheet, View, Text, Button} from&#8217;react-native&#8217;;<\/span><\/p>\n<pre class=\"theme:github font-size:14 nums:false lang:default decode:true\">\/\/ Function to get permission for location\r\n\r\nconst requestLocationPermission = async () =&gt; {\r\n\r\n\u00a0\u00a0try {\r\n\r\n\u00a0\u00a0\u00a0\u00a0const granted = await PermissionsAndroid.request(\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0title: 'Geolocation Permission',\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0message: 'Can we access your location?',\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0buttonNeutral: 'Ask Me Later',\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0buttonNegative: 'Cancel',\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0buttonPositive: 'OK',\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0},\r\n\r\n\u00a0\u00a0\u00a0\u00a0);\r\n\r\n\u00a0\u00a0\u00a0\u00a0console.log('granted', granted);\r\n\r\n\u00a0\u00a0\u00a0\u00a0if (granted === 'granted') {\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0console.log('You can use Geolocation');\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return true;\r\n\r\n\u00a0\u00a0\u00a0\u00a0} else {\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0console.log('You cannot use Geolocation');\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return false;\r\n\r\n\u00a0\u00a0\u00a0\u00a0}\r\n\r\n\u00a0\u00a0} catch (err) {\r\n\r\n\u00a0\u00a0\u00a0\u00a0return false;\r\n\r\n\u00a0\u00a0}\r\n\r\n};<\/pre>\n<p><span style=\"font-weight: 400;\">You may try this unified iOS\/Android permissions library or read articles on iOS permission flow for information on<\/span><a href=\"https:\/\/www.npmjs.com\/package\/react-native-permissions\"><span style=\"font-weight: 400;\"> iOS app permissions<\/span><\/a><span style=\"font-weight: 400;\">.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">To ask the issuer for authorization, we call the request function in the code above.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Next, we supply an object containing the prompt&#8217;s information. We return true if the request was successful and false otherwise.<\/span><\/p>\n<h3><span class=\"ez-toc-section\" id=\"Obtaining-the-users-location-information\"><\/span><span style=\"font-weight: 400;\">Obtaining the user&#8217;s location information<\/span><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p><span style=\"font-weight: 400;\">We will now establish a state to monitor our users&#8217; whereabouts from within our component.<\/span><\/p>\n<pre class=\"theme:github font-size:14 nums:false lang:default decode:true\">\u00a0\/\/ state to hold location\r\n\r\n\u00a0\u00a0const [location, setLocation] = useState(false);<\/pre>\n<p><span style=\"font-weight: 400;\">Next, we&#8217;ll create a function that will ask for permission when the GET LOCATION button is touched. If authorization is given, the user&#8217;s current location will be obtained:<\/span><\/p>\n<pre class=\"theme:github font-size:14 nums:false lang:default decode:true \">\u00a0\/\/ function to check permissions and get Location\r\n\r\n\u00a0\u00a0const getLocation = () =&gt; {\r\n\r\n\u00a0\u00a0\u00a0\u00a0const result = requestLocationPermission();\r\n\r\n\u00a0\u00a0\u00a0\u00a0result.then(res =&gt; {\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0console.log('res is:', res);\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0if (res) {\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Geolocation.getCurrentPosition(\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0position =&gt; {\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0console.log(position);\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0setLocation(position);\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0},\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0error =&gt; {\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ See error code charts below.\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0console.log(error.code, error.message);\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0setLocation(false);\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0},\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{enableHighAccuracy: true, timeout: 15000, maximumAge: 10000},\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0);\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\r\n\r\n\u00a0\u00a0\u00a0\u00a0});\r\n\r\n\u00a0\u00a0\u00a0\u00a0console.log(location);\r\n\r\n\u00a0\u00a0};<\/pre>\n<p><span style=\"font-weight: 400;\">We observe ourselves calling the previously written requestLocationPermission function, which returns a promise that can resolve to yes or false. We use the react-native-geolocation-service library to obtain the precise position and set the location state to the result if the promise resolves to true. It will set the location state to false if the promise is false, indicating that authorization was not granted, or if it is unable to obtain the location.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Next, we add the getLocation method to the GET LOCATION button as an onPress event:<\/span><\/p>\n<pre class=\"theme:github font-size:14 nums:false lang:default decode:true\">&lt;Button title=\"Get Location\" onPress={getLocation} \/&gt;<\/pre>\n<h4><span class=\"ez-toc-section\" id=\"As-of-right-now-your-Appjs-code-ought-to-resemble-this\"><\/span><span style=\"font-weight: 400;\">As of right now, your App.js code ought to resemble this:<\/span><span class=\"ez-toc-section-end\"><\/span><\/h4>\n<pre class=\"theme:github font-size:14 nums:false lang:default decode:true\">\/**\r\n\r\n\u00a0* Sample React Native App\r\n\r\n\u00a0* https:\/\/github.com\/facebook\/react-native\r\n\r\n\u00a0*\r\n\r\n\u00a0* @format\r\n\r\n\u00a0* @flow strict-local\r\n\r\n\u00a0*\/\r\n\r\nimport React, {useState, useEffect} from 'react';\r\n\r\nimport {StyleSheet, View, Text, Button, PermissionsAndroid} from 'react-native';\r\n\r\nimport Geolocation from 'react-native-geolocation-service';\r\n\r\n\/\/ Function to get permission for location\r\n\r\nconst requestLocationPermission = async () =&gt; {\r\n\r\n\u00a0\u00a0try {\r\n\r\n\u00a0\u00a0\u00a0\u00a0const granted = await PermissionsAndroid.request(\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0title: 'Geolocation Permission',\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0message: 'Can we access your location?',\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0buttonNeutral: 'Ask Me Later',\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0buttonNegative: 'Cancel',\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0buttonPositive: 'OK',\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0},\r\n\r\n\u00a0\u00a0\u00a0\u00a0);\r\n\r\n\u00a0\u00a0\u00a0\u00a0console.log('granted', granted);\r\n\r\n\u00a0\u00a0\u00a0\u00a0if (granted === 'granted') {\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0console.log('You can use Geolocation');\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return true;\r\n\r\n\u00a0\u00a0\u00a0\u00a0} else {\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0console.log('You cannot use Geolocation');\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return false;\r\n\r\n\u00a0\u00a0\u00a0\u00a0}\r\n\r\n\u00a0\u00a0} catch (err) {\r\n\r\n\u00a0\u00a0\u00a0\u00a0return false;\r\n\r\n\u00a0\u00a0}\r\n\r\n};\r\n\r\nconst App = () =&gt; {\r\n\r\n\u00a0\u00a0\/\/ state to hold location\r\n\r\n\u00a0\u00a0const [location, setLocation] = useState(false);\r\n\r\n\u00a0\u00a0\/\/ function to check permissions and get Location\r\n\r\n\u00a0\u00a0const getLocation = () =&gt; {\r\n\r\n\u00a0\u00a0\u00a0\u00a0const result = requestLocationPermission();\r\n\r\n\u00a0\u00a0\u00a0\u00a0result.then(res =&gt; {\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0console.log('res is:', res);\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0if (res) {\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Geolocation.getCurrentPosition(\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0position =&gt; {\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0console.log(position);\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0setLocation(position);\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0},\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0error =&gt; {\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ See error code charts below.\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0console.log(error.code, error.message);\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0setLocation(false);\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0},\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{enableHighAccuracy: true, timeout: 15000, maximumAge: 10000},\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0);\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\r\n\r\n\u00a0\u00a0\u00a0\u00a0});\r\n\r\n\u00a0\u00a0\u00a0\u00a0console.log(location);\r\n\r\n\u00a0\u00a0};\r\n\r\n\u00a0\u00a0return (\r\n\r\n\u00a0\u00a0\u00a0\u00a0&lt;View style={styles.container}&gt;\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;Text&gt;Welcome!&lt;\/Text&gt;\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;View\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0style={{marginTop: 10, padding: 10, borderRadius: 10, width: '40%'}}&gt;\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;Button title=\"Get Location\" onPress={getLocation} \/&gt;\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;\/View&gt;\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;Text&gt;Latitude: {location ? location.coords.latitude : null}&lt;\/Text&gt;\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;Text&gt;Longitude: {location ? location.coords.longitude : null}&lt;\/Text&gt;\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;View\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0style={{marginTop: 10, padding: 10, borderRadius: 10, width: '40%'}}&gt;\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;Button title=\"Send Location\" \/&gt;\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;\/View&gt;\r\n\r\n\u00a0\u00a0\u00a0\u00a0&lt;\/View&gt;\r\n\r\n\u00a0\u00a0);\r\n\r\n};\r\n\r\nconst styles = StyleSheet.create({\r\n\r\n\u00a0\u00a0container: {\r\n\r\n\u00a0\u00a0\u00a0\u00a0flex: 1,\r\n\r\n\u00a0\u00a0\u00a0\u00a0backgroundColor: '#fff',\r\n\r\n\u00a0\u00a0\u00a0\u00a0alignItems: 'center',\r\n\r\n\u00a0\u00a0\u00a0\u00a0justifyContent: 'center',\r\n\r\n\u00a0\u00a0},\r\n\r\n});\r\n\r\nexport default App;<\/pre>\n<p><span style=\"font-weight: 400;\">When it launches and you select the GET LOCATION button, the following pop-up window will appear:<\/span><\/p>\n<p><img decoding=\"async\" class=\"wp-image-8655 aligncenter\" src=\"https:\/\/dianapps.com\/blog\/wp-content\/uploads\/2024\/03\/image10.png\" alt=\"\" width=\"277\" height=\"495\" \/><\/p>\n<p><img decoding=\"async\" class=\"wp-image-8656 aligncenter\" src=\"https:\/\/dianapps.com\/blog\/wp-content\/uploads\/2024\/03\/image9.png\" alt=\"\" width=\"288\" height=\"519\" \/><\/p>\n<p><span style=\"font-weight: 400;\">After that, the screen ought to display your location as seen below:<\/span><\/p>\n<p><img decoding=\"async\" class=\"wp-image-8657 aligncenter\" src=\"https:\/\/dianapps.com\/blog\/wp-content\/uploads\/2024\/03\/image8.png\" alt=\"\" width=\"307\" height=\"546\" \/><\/p>\n<h2><span class=\"ez-toc-section\" id=\"The-Location-Entity\"><\/span><span style=\"font-weight: 400;\">The Location Entity<\/span><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-weight: 400;\">React-native-geolocation-service will provide a location object that resembles the following code:<\/span><\/p>\n<pre class=\"theme:github font-size:14 nums:false lang:default decode:true\">{\r\n\r\n\u00a0\u00a0\"coords\": {\r\n\r\n\u00a0\u00a0\u00a0\u00a0\"accuracy\": 5,\r\n\r\n\u00a0\u00a0\u00a0\u00a0\"altitude\": 5,\r\n\r\n\u00a0\u00a0\u00a0\u00a0\"altitudeAccuracy\": 0.5,\r\n\r\n\u00a0\u00a0\u00a0\u00a0\"heading\": 0,\r\n\r\n\u00a0\u00a0\u00a0\u00a0\"latitude\": 37.4219983,\r\n\r\n\u00a0\u00a0\u00a0\u00a0\"longitude\": -122.084,\r\n\r\n\u00a0\u00a0\u00a0\u00a0\"speed\": 0\r\n\r\n\u00a0\u00a0},\r\n\r\n\u00a0\u00a0\"mocked\": false,\r\n\r\n\u00a0\u00a0\"provider\": \"fused\",\r\n\r\n\u00a0\u00a0\"timestamp\": 1662837540458\r\n\r\n}<\/pre>\n<h2><span class=\"ez-toc-section\" id=\"Geolocation-data-transmission-in-React-Native\"><\/span><span style=\"font-weight: 400;\">Geolocation data transmission in React Native<\/span><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-weight: 400;\">We only need to change the communicate LOCATION button into a Tweet button to communicate the user&#8217;s geolocation data to Twitter.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">We&#8217;ll show the data returned in the example before sending the user the location. Add the useState Hook from React to our project in the following way to do this:<\/span><\/p>\n<pre class=\"theme:github font-size:14 nums:false lang:default decode:true\">import React, { useState } from 'react';<\/pre>\n<p><span style=\"font-weight: 400;\">Then, under our App function, we define a state:<\/span><\/p>\n<pre class=\"theme:github font-size:14 nums:false lang:default decode:true\">useState([]) = [viewLocation, isViewLocation]<\/pre>\n<p><span style=\"font-weight: 400;\">We call the isViewLocation function and update the viewLocation array with the location information object by updating the if expression as follows:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">isViewLocation(reference)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Update the Location and Longitude text tags to see the information returned:<\/span><\/p>\n<pre class=\"theme:github font-size:14 nums:false lang:default decode:true\">Longitude: {viewLocation.longitude} Latitude: {viewLocation.latitude}<\/pre>\n<p><span style=\"font-weight: 400;\">viewLocation.The function isViewLocation calls the object response, and latitude returns the latitude in that response. For the longitude, the same holds.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">We may now update the button to notify Twitter of the user&#8217;s location. Below is a screenshot of our last sample application:<\/span><\/p>\n<p><img decoding=\"async\" class=\"wp-image-8658 aligncenter\" src=\"https:\/\/dianapps.com\/blog\/wp-content\/uploads\/2024\/03\/image6.png\" alt=\"\" width=\"265\" height=\"571\" \/><\/p>\n<h2><span class=\"ez-toc-section\" id=\"Send-User-Location-Data-to-Twitter\"><\/span><span style=\"font-weight: 400;\">Send User Location Data to Twitter<\/span><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-weight: 400;\">Next, ask your mobile app development company to configure and include the user&#8217;s location in a new Tweet using the SEND LOCATION button:<\/span><\/p>\n<pre class=\"theme:github font-size:14 nums:false lang:default decode:true\">\/\/ Function to Send Location to twitter\r\n\r\n\u00a0\u00a0const sendLocation = () =&gt; {\r\n\r\n\u00a0\u00a0\u00a0\u00a0try {\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0if (location) {\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0const tweet = `latitude is ${location.coords.latitude} and longitude is ${location.coords.longitude}`;\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0const url = `https:\/\/twitter.com\/intent\/tweet?text=${tweet}`;\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Linking.openURL(url);\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\r\n\r\n\u00a0\u00a0\u00a0\u00a0} catch (error) {\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0console.log(error);\r\n\r\n\u00a0\u00a0\u00a0\u00a0}\r\n\r\n\u00a0\u00a0};<\/pre>\n<h4><span class=\"ez-toc-section\" id=\"The-aforementioned-function\"><\/span><span style=\"font-weight: 400;\">The aforementioned function<\/span><span class=\"ez-toc-section-end\"><\/span><\/h4>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Determines if our location is in our state.\u00a0<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Location will equal false if we don&#8217;t.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Creates a string containing our latitude and longitude to serve as our tweet.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Builds a URL to generate the tweet.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Opens the URL by using the Linking object.\u00a0<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Link &amp; Import from React Native<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">You should now see a browser window that resembles the following image when you click the SEND LOCATION button:<\/span><\/p>\n<p><img decoding=\"async\" class=\"wp-image-8659 aligncenter\" src=\"https:\/\/dianapps.com\/blog\/wp-content\/uploads\/2024\/03\/image5.png\" alt=\"\" width=\"321\" height=\"692\" \/><\/p>\n<h4><span class=\"ez-toc-section\" id=\"The-following-code-should-be-present-in-the-final-Appjs-file\"><\/span><span style=\"font-weight: 400;\">The following code should be present in the final App.js file:<\/span><span class=\"ez-toc-section-end\"><\/span><\/h4>\n<pre class=\"theme:github font-size:14 nums:false lang:default decode:true\">\/**\r\n\r\n\u00a0* Sample React Native App\r\n\r\n\u00a0* https:\/\/github.com\/facebook\/react-native\r\n\r\n\u00a0*\r\n\r\n\u00a0* @format\r\n\r\n\u00a0* @flow strict-local\r\n\r\n\u00a0*\/\r\n\r\nimport React, {useState, useEffect} from 'react';\r\n\r\nimport {\r\n\r\n\u00a0\u00a0StyleSheet,\r\n\r\n\u00a0\u00a0View,\r\n\r\n\u00a0\u00a0Text,\r\n\r\n\u00a0\u00a0Button,\r\n\r\n\u00a0\u00a0PermissionsAndroid,\r\n\r\n\u00a0\u00a0Linking,\r\n\r\n} from 'react-native';\r\n\r\nimport Geolocation from 'react-native-geolocation-service';\r\n\r\n\/\/ Function to get permission for location\r\n\r\nconst requestLocationPermission = async () =&gt; {\r\n\r\n\u00a0\u00a0try {\r\n\r\n\u00a0\u00a0\u00a0\u00a0const granted = await PermissionsAndroid.request(\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0title: 'Geolocation Permission',\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0message: 'Can we access your location?',\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0buttonNeutral: 'Ask Me Later',\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0buttonNegative: 'Cancel',\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0buttonPositive: 'OK',\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0},\r\n\r\n\u00a0\u00a0\u00a0\u00a0);\r\n\r\n\u00a0\u00a0\u00a0\u00a0console.log('granted', granted);\r\n\r\n\u00a0\u00a0\u00a0\u00a0if (granted === 'granted') {\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0console.log('You can use Geolocation');\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return true;\r\n\r\n\u00a0\u00a0\u00a0\u00a0} else {\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0console.log('You cannot use Geolocation');\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return false;\r\n\r\n\u00a0\u00a0\u00a0\u00a0}\r\n\r\n\u00a0\u00a0} catch (err) {\r\n\r\n\u00a0\u00a0\u00a0\u00a0return false;\r\n\r\n\u00a0\u00a0}\r\n\r\n};\r\n\r\nconst App = () =&gt; {\r\n\r\n\u00a0\u00a0\/\/ state to hold location\r\n\r\n\u00a0\u00a0const [location, setLocation] = useState(false);\r\n\r\n\u00a0\u00a0\/\/ function to check permissions and get Location\r\n\r\n\u00a0\u00a0const getLocation = () =&gt; {\r\n\r\n\u00a0\u00a0\u00a0\u00a0const result = requestLocationPermission();\r\n\r\n\u00a0\u00a0\u00a0\u00a0result.then(res =&gt; {\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0console.log('res is:', res);\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0if (res) {\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Geolocation.getCurrentPosition(\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0position =&gt; {\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0console.log(position);\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0setLocation(position);\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0},\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0error =&gt; {\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ See error code charts below.\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0console.log(error.code, error.message);\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0setLocation(false);\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0},\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{enableHighAccuracy: true, timeout: 15000, maximumAge: 10000},\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0);\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\r\n\r\n\u00a0\u00a0\u00a0\u00a0});\r\n\r\n\u00a0\u00a0\u00a0\u00a0console.log(location);\r\n\r\n\u00a0\u00a0};\r\n\r\n\u00a0\u00a0\/\/ Function to Send Location to twitter\r\n\r\n\u00a0\u00a0const sendLocation = () =&gt; {\r\n\r\n\u00a0\u00a0\u00a0\u00a0try {\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0if (location) {\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0const tweet = `latitude is ${location.coords.latitude} and longitude is ${location.coords.longitude}`;\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0const url = `https:\/\/twitter.com\/intent\/tweet?text=${tweet}`;\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Linking.openURL(url);\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\r\n\r\n\u00a0\u00a0\u00a0\u00a0} catch (error) {\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0console.log(error);\r\n\r\n\u00a0\u00a0\u00a0\u00a0}\r\n\r\n\u00a0\u00a0};\r\n\r\n\u00a0\u00a0return (\r\n\r\n\u00a0\u00a0\u00a0\u00a0&lt;View style={styles.container}&gt;\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;Text&gt;Welcome!&lt;\/Text&gt;\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;View\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0style={{marginTop: 10, padding: 10, borderRadius: 10, width: '40%'}}&gt;\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;Button title=\"Get Location\" onPress={getLocation} \/&gt;\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;\/View&gt;\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;Text&gt;Latitude: {location ? location.coords.latitude : null}&lt;\/Text&gt;\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;Text&gt;Longitude: {location ? location.coords.longitude : null}&lt;\/Text&gt;\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;View\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0style={{marginTop: 10, padding: 10, borderRadius: 10, width: '40%'}}&gt;\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;Button title=\"Send Location\" onPress={sendLocation} \/&gt;\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;\/View&gt;\r\n\r\n\u00a0\u00a0\u00a0\u00a0&lt;\/View&gt;\r\n\r\n\u00a0\u00a0);\r\n\r\n};\r\n\r\nconst styles = StyleSheet.create({\r\n\r\n\u00a0\u00a0container: {\r\n\r\n\u00a0\u00a0\u00a0\u00a0flex: 1,\r\n\r\n\u00a0\u00a0\u00a0\u00a0backgroundColor: '#fff',\r\n\r\n\u00a0\u00a0\u00a0\u00a0alignItems: 'center',\r\n\r\n\u00a0\u00a0\u00a0\u00a0justifyContent: 'center',\r\n\r\n\u00a0\u00a0},\r\n\r\n});\r\n\r\nexport default App;<\/pre>\n<h2><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span><span style=\"font-weight: 400;\">Conclusion<\/span><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-weight: 400;\">There&#8217;s much more you can do with the location of a user now that you know how to get it. You may create an emergency button alert system, track a user, and even create a delivery service. There are countless options. We just touched the surface of the react-native-geolocation-service library in this tutorial, which we used to create our sample application.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">If you&#8217;re looking for a user-friendly solution that provides precise location data on a website instead of a mobile app then you can explore<\/span><\/p>\n<p><span style=\"font-weight: 400;\"><a href=\"https:\/\/iplocation.io\/my-location\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/iplocation.io\/my-location<\/a> for seamless location viewing in a browser.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">The characteristics of geolocation are intriguing and have many practical applications. If you intend to utilize geolocation in your React Native project, let us know in the comments. Have fun with coding!<\/span><\/p>\n<p><a href=\"https:\/\/dianapps.com\/hire-developer\"><b>Hire DianApps app developers<\/b><\/a><span style=\"font-weight: 400;\"> to use the geolocation service in your business so that people can find you in a better and more efficient way.\u00a0<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>You may have questioned how ride-hailing and food delivery services determine your current location. Ever come across the term Geolocation? We&#8217;ll learn how to use geolocation in React Native in this tutorial. We&#8217;ll create an example application that allows the user to submit their position to another source, such as Twitter, and shows their location [&hellip;]<\/p>\n","protected":false},"author":4,"featured_media":8661,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_wp_applaud_exclude":false,"footnotes":""},"categories":[3,1],"tags":[563],"class_list":["post-8647","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-app-development","category-business","tag-react-native-geolocation-service"],"featured_image_src":{"landsacpe":["https:\/\/dianapps.com\/blog\/wp-content\/uploads\/2024\/03\/Geolocation-min-1140x445.jpg",1140,445,true],"list":["https:\/\/dianapps.com\/blog\/wp-content\/uploads\/2024\/03\/Geolocation-min-463x348.jpg",463,348,true],"medium":["https:\/\/dianapps.com\/blog\/wp-content\/uploads\/2024\/03\/Geolocation-min-300x169.jpg",300,169,true],"full":["https:\/\/dianapps.com\/blog\/wp-content\/uploads\/2024\/03\/Geolocation-min-scaled.jpg",2560,1440,false]},"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.12 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to use React Native Geolocation Service?<\/title>\n<meta name=\"description\" content=\"Learn to integrate React Native Geolocation for precise location-based services. Master GPS functionalities with robust mobile app development.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/dianapps.com\/blog\/how-to-use-react-native-geolocation-service\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to use React Native Geolocation Service?\" \/>\n<meta property=\"og:description\" content=\"Learn to integrate React Native Geolocation for precise location-based services. Master GPS functionalities with robust mobile app development.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/dianapps.com\/blog\/how-to-use-react-native-geolocation-service\/\" \/>\n<meta property=\"og:site_name\" content=\"Learn About Digital Transformation &amp; Development | DianApps Blog\" \/>\n<meta property=\"article:published_time\" content=\"2024-03-01T13:07:56+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-04-17T11:38:52+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/dianapps.com\/blog\/wp-content\/uploads\/2024\/03\/Geolocation-min-scaled.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"2560\" \/>\n\t<meta property=\"og:image:height\" content=\"1440\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Harshita Sharma\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Harshita Sharma\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"12 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to use React Native Geolocation Service?","description":"Learn to integrate React Native Geolocation for precise location-based services. Master GPS functionalities with robust mobile app development.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/dianapps.com\/blog\/how-to-use-react-native-geolocation-service\/","og_locale":"en_US","og_type":"article","og_title":"How to use React Native Geolocation Service?","og_description":"Learn to integrate React Native Geolocation for precise location-based services. Master GPS functionalities with robust mobile app development.","og_url":"https:\/\/dianapps.com\/blog\/how-to-use-react-native-geolocation-service\/","og_site_name":"Learn About Digital Transformation &amp; Development | DianApps Blog","article_published_time":"2024-03-01T13:07:56+00:00","article_modified_time":"2024-04-17T11:38:52+00:00","og_image":[{"width":2560,"height":1440,"url":"https:\/\/dianapps.com\/blog\/wp-content\/uploads\/2024\/03\/Geolocation-min-scaled.jpg","type":"image\/jpeg"}],"author":"Harshita Sharma","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Harshita Sharma","Est. reading time":"12 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/dianapps.com\/blog\/how-to-use-react-native-geolocation-service\/","url":"https:\/\/dianapps.com\/blog\/how-to-use-react-native-geolocation-service\/","name":"How to use React Native Geolocation Service?","isPartOf":{"@id":"https:\/\/dianapps.com\/blog\/#website"},"datePublished":"2024-03-01T13:07:56+00:00","dateModified":"2024-04-17T11:38:52+00:00","author":{"@id":"https:\/\/dianapps.com\/blog\/#\/schema\/person\/6672b5142fe10cc5379a72656c884045"},"description":"Learn to integrate React Native Geolocation for precise location-based services. Master GPS functionalities with robust mobile app development.","breadcrumb":{"@id":"https:\/\/dianapps.com\/blog\/how-to-use-react-native-geolocation-service\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/dianapps.com\/blog\/how-to-use-react-native-geolocation-service\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/dianapps.com\/blog\/how-to-use-react-native-geolocation-service\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/dianapps.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How to use React Native Geolocation Service?"}]},{"@type":"WebSite","@id":"https:\/\/dianapps.com\/blog\/#website","url":"https:\/\/dianapps.com\/blog\/","name":"Learn About Digital Transformation &amp; Development | DianApps Blog","description":"Dianapps","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/dianapps.com\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/dianapps.com\/blog\/#\/schema\/person\/6672b5142fe10cc5379a72656c884045","name":"Harshita Sharma","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/dianapps.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/dianapps.com\/blog\/wp-content\/uploads\/2025\/04\/unnamed-96x96.png","contentUrl":"https:\/\/dianapps.com\/blog\/wp-content\/uploads\/2025\/04\/unnamed-96x96.png","caption":"Harshita Sharma"},"description":"A competent and enthusiastic writer, having excellent persuasive skills in the tech, marketing, and event industry. With vast knowledge about the latest industry trends, she is familiar with creating engaging content gigs.","sameAs":["https:\/\/www.linkedin.com\/in\/harshita-sharma-958662198"],"url":"https:\/\/dianapps.com\/blog\/author\/harshita\/"}]}},"_links":{"self":[{"href":"https:\/\/dianapps.com\/blog\/wp-json\/wp\/v2\/posts\/8647","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dianapps.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dianapps.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dianapps.com\/blog\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/dianapps.com\/blog\/wp-json\/wp\/v2\/comments?post=8647"}],"version-history":[{"count":6,"href":"https:\/\/dianapps.com\/blog\/wp-json\/wp\/v2\/posts\/8647\/revisions"}],"predecessor-version":[{"id":9021,"href":"https:\/\/dianapps.com\/blog\/wp-json\/wp\/v2\/posts\/8647\/revisions\/9021"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/dianapps.com\/blog\/wp-json\/wp\/v2\/media\/8661"}],"wp:attachment":[{"href":"https:\/\/dianapps.com\/blog\/wp-json\/wp\/v2\/media?parent=8647"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dianapps.com\/blog\/wp-json\/wp\/v2\/categories?post=8647"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dianapps.com\/blog\/wp-json\/wp\/v2\/tags?post=8647"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}