I’ve been using the Geolocation API in React Native a fair amount lately. It’s an API that I didn’t realize existed in React Native and definitely didn’t realize how easy it was to actually use.\n\nReact Native has some great polyfills that bring APIs that we’ve gotten used to on the web to mobile which makes using them insanely easy. The Geolocation API in React Native is simply an extension of the web spec. This post will basically be a rehash of the official documentation with some additional commentary and examples. I encourage you to read the official documentation in addition to this.\n\n* [_React Native Geolocation_](https://facebook.github.io/react-native/docs/geolocation.html)\n* [_Web Geolocation API_](https://developer.mozilla.org/en-US/docs/Web/API/Geolocation)\n\n#### Installation\n\nInstallation is really straightforward. On iOS the necessary key in the Info.plist (_NSLocationWhenInUseUsageDescription_) is already set when you create a new app. If you want to use a user’s location when the app is in the background you’ll have to do [some additional configuration](https://facebook.github.io/react-native/docs/geolocation.html#ios).\n\nOn Android it’s similarly simple, just not enabled by default. In your _AndroidManifest.xml_ you’ll need to add the following permission request\n\n<uses-permission android:name="android.permission.ACCESS\\_FINE\\_LOCATION" />\n\nThe reason it comes enabled by default on iOS but not Android comes down to how & when each platform requests permission to use location data. On iOS permission is requested the first time you try to use it, on Android it’s requested upon app download. Because of this if the location permission came enabled by default on Android a user will see what it’s requesting (location data) and if your app doesn’t have a good reason to need their location information then they may not download your app.\n\n#### API Overview\n\nThe geolocation api exists on the global `navigator` object in React Native, just like on the web, so you would access it via `navigator.geolocation`.\n\nI’ll be covering three of the methods available on `navigator.geolocation` — `getCurrentPosition`, `watchPosition`, and `clearWatch`.\n\n**getCurrentPosition** allows us to request a user’s location at any time. It accepts three parameters — a success callback, an error callback, and a configuration object (in that order). The success callback will be passed an object that looks like\n\nThe error callback will be passed a standard error message. And finally the config object has\n\n* _enableHighAccuracy_ _(boolean)_— which allows you to get the most accurate location. Due to how it gets the location (via GPS) it may be slower to return a result but it will be more accurate when enabled.\n* _timeout (milliseconds)_— how long does the API have to return the position before throwing an error?\n* _maximumAge (milliseconds)_ — if a location exists in the device cache, how old can it be before it’s no longer valuable to your app?\n\n**watchPosition** is very similar to getCurrentPosition. The only difference is that the success or error callback will be called whenever the user’s location updates. There’s also an extra option in the config object and that’s `distanceFilter` this will allow you to specify how many meters a user has to move before a callback is triggered again.\n\n**clearWatch** should be used any time `watchPosition` is used. This will tell the device that your app no longer needs location information. Just like you should always clear an interval, you should always clear a position watch when the app unmounts or you no longer need it.\n\n#### _getCurrentPosition_ Example\n\nYou can see above just how simple it is to access the current location with this API.\n\n#### watchPosition Example\n\nYou can see there that using watch position is very similar to fetching the position, it just happens whenever the location changes. It’s important to note two things\n\n1. Make sure to clear the watch when the component is unmounted (see line 30)\n2. If you don’t need realtime updating location information use _getCurrentPosition_ instead as it will be less battery intensive\n\n> Want to see what using Geolocation is like in a production quality app? Checkout [this React Native course](https://learn.handlebarlabs.com/p/react-native-meteor) (one of many)!\n\n> [Hacker Noon](http://bit.ly/Hackernoon) is how hackers start their afternoons. We’re a part of the [@AMI](http://bit.ly/atAMIatAMI)family. We are now [accepting submissions](http://bit.ly/hackernoonsubmission) and happy to [discuss advertising &sponsorship](mailto:firstname.lastname@example.org) opportunities.\n\n> To learn more, [read our about page](https://goo.gl/4ofytp), [like/message us on Facebook](http://bit.ly/HackernoonFB), or simply, [tweet/DM @HackerNoon.](https://goo.gl/k7XYbx)\n\n> If you enjoyed this story, we recommend reading our [latest tech stories](http://bit.ly/hackernoonlatestt) and [trending tech stories](https://hackernoon.com/trending). Until next time, don’t take the realities of the world for granted!