react-native-background-location-tracker
this library tracks users location even when the app completely swiped. and sends the data to your backend controller. the only way to stop the service is StopLocationService method.
Getting started
$ npm install react-native-background-location-tracker --save
Mostly automatic installation
$ react-native link react-native-background-location-tracker
Manual installation
iOS
Not Supported Yet , Comming Soon
Android
- Open up
android/app/src/main/java/[...]/MainApplication.java
- Add
import com.backgroundlocationtracker.sajjadBackgroundLocationTrackerPackage;
to the imports at the top of the file - Add
new sajjadBackgroundLocationTrackerPackage()
to the list returned by thegetPackages()
method
- Append the following lines to
android/settings.gradle
:include ':react-native-background-location-tracker' project(':react-native-background-location-tracker').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-background-location-tracker/android')
- Insert the following lines inside the dependencies block in
android/app/build.gradle
:compile project(':react-native-background-location-tracker')
Usage
you need a backend controller to receive 'application/json' type post params (Receives An AuthKey Param, Latitude Param, Longitude Param)
set the name of params and backend controller link and other data to StartLocationService method like below example
to stop the service use StopLocationService method.
;;; const instructions = Platform; type Props = {};<Props> { return <View style=stylescontainer> <TouchableOpacity onPress= { BackgroundLocationTracking; } style=width: '90%' height: 36 backgroundColor: "#03A9F4" borderRadius: 4 margin: 16/> <TouchableOpacity onPress= { BackgroundLocationTracking; } style=width: '90%' height: 36 backgroundColor: "#03A9F4" borderRadius: 4 margin: 16/> <Text style=styleswelcome>Welcome to React Native!</Text> <Text style=stylesinstructions>To get started edit Appjs</Text> <Text style=stylesinstructions>instructions</Text> </View> ; } const styles = StyleSheet;