diff --git a/README.md b/README.md index 81c5a66..b07e530 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,7 @@ Since this library was meant to be a drop-in replacement for the RN's Geolocatio > One thing to note, for android this library assumes that location permission is already granted by the user, so you have to use `PermissionsAndroid` to request for permission before making the location request. +Class component: ```js ... import Geolocation from 'react-native-geolocation-service'; @@ -54,6 +55,28 @@ componentDidMount() { } ``` +Functional component: +```js +... +import { useEffect } from 'react'; +import Geolocation from 'react-native-geolocation-service'; +... + useEffect(() => { + if (hasLocationPermission) { + Geolocation.getCurrentPosition( + (position) => { + console.log(position); + }, + (error) => { + // See error code charts below. + console.log(error.code, error.message); + }, + { enableHighAccuracy: true, timeout: 15000, maximumAge: 10000 } + ); + } + }, []); +``` + # API #### `async requestAuthorization(authorizationLevel) (iOS only)` Request location permission based on the authorizationLevel parameter. Can be either `"whenInUse"` or `"always"`. You have to configure the plist keys during setup. @@ -132,4 +155,4 @@ Stops observing for device location changes. In addition, it removes all listene - OnePlus (using OxygenOS Settings): Battery > battery optimization > switch to 'all apps' > select your app > don't optimize - Samsung: Access battery settings > app power saving > details > your app > disabled - Sony If you're running Android 6 or higher: Battery > from the menu in the upper right-hand corner > battery optimization > apps > your app - - Xiaomi (MIUI OS) If you're running Android 6 or higher: Access your phone settings > additional settings > battery and performance > manage battery usage > apps > your app + - Xiaomi (MIUI OS) If you're running Android 6 or higher: Access your phone settings > additional settings > battery and performance > manage battery usage > apps > your app \ No newline at end of file