0.1.6 • Published 7 months ago

react-native-bg-location v0.1.6

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

You can utilize this npm package on iOS right now, and we're in the process of bringing it to Android.

react-native-bg-location

You can utilize this npm package on iOS right now, and we're in the process of bringing it to Android.

The react-native-bg-location package is a versatile and easy-to-use library for handling background location tracking in React Native applications. It provides a seamless way to access the device's location in the background, making it suitable for various use cases, including tracking user movements, geofencing.

Installation for ios

npm install react-native-bg-location

```bash

cd ios && pod install

Configure Background Capabilities

Open your App in XCode and select the root of your project. Select Capabilities tab. Enable Background Modes and enable the following modes:

  • Location updates
  • Background fetch

Configure Usage Strings in Info.plist

Edit Info.plist. Add the following items (Set Value as desired):

KeyTypeValue
Privacy - Location Always and When in Use Usage DescriptionStringCHANGEME: Location required in background
Privacy - Location When in Use Usage DescriptionStringCHANGEME: Location required when app is in use
Privacy - Motion Usage DescriptionStringCHANGEME: Motion permission helps detect when device in in-motion

Demo video

https://github.com/gulsher7/react-native-bg-location/assets/56266123/1ddc7db2-d07c-49d2-8bb4-b07d1b669847

## Usage

```js
import { LocationEvent, setDesiredDistance, startLocation, stopLocation } from 'react-native-bg-location';

// ...
    
 1. setDesiredDistance(distance: number)

This function sets the desired distance for location updates. 
It takes a numeric parameter distance (in meters) and returns a Promise. 
It fetches the location after the device moves the specified distance.

   
setDesiredDistance(50).then((res) => {  //example send value in meters
    console.log(res)
  }).catch((error) => {
    console.log("Error code:", error);
  })

2. startLocation()
   use this function to start location tracking. It continuously updates the device's location.
  

3. stopLocation()
   To stop location tracking, call this function.

4. LocationEvent.addListener(eventType: string, callback: (data: any) => void)

    LocationEvent.addListener("LAT_LNG", (latlng) => { //example
    console.log("data", latlng);
    });

5. LocationEvent.removeAllListeners(eventType: string)
   To remove all listeners for a specific event type, you can use this function. 
   
   LocationEvent.removeAllListeners("LAT_LNG"); //example

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

License

MIT


Made with create-react-native-library

0.1.6

7 months ago

0.1.5

7 months ago

0.1.4

7 months ago

0.1.3

7 months ago

0.1.2

7 months ago

0.1.1

7 months ago

0.1.0

7 months ago