How can I use this library for location tracking task?
I am trying to understand how this library works by running it on my phone. It works great so far but how can I use it for location tracking task?
I am building an app where it requires conscience when it goes to background. The app would actively track user' coordinates (not by the interval, but according to the updates emit by the user' walking activity).
I've run the example and notice a few features. When the app goes into the background, it runs the job every 5 seconds. But when I lock my phone, it hardly runs the job, more like every 1 - 2 minute. If I understand correctly, it's Android that's trying to save battery.
So it isn't practical if I encapsulate my LocationManager GPS function inside the register() method, right? For example, if the phone is locked, and register() method only gets called every 2 minutes, then watchPosition() would not be called, if somehow, Android kills my app because of its running low on memory.
BackgroundJob.register({
jobKey: myJobKey,
job: () => {
this.location = navigator.geolocation.watchPosition(({ coords}) => {
// other methods
})
}
});
Ultimately I just need something to keep the app alive so that my other methods can run happily.
Try the option alwaysRunning
@vikeri Got this error #32 and I'm not sure how and whether I should create a dummy method to keep all my other business logics alive.
@vikeri where I can add alwaysRunning? I didn't see any docs which mention that.
@pewh It was quite unstable so it was deprecated unfortunately in 2.0.0, but it could in theory be reimplemented by looking at the old code.
I have used this module to track location in every 15 min. In that case I have set a task called trackLocation and in trackLocation function I have used the coding for trackLocation. I have defined the task in the following way.
const backgroundJob = { jobKey: "myJob", period : 900000, timeout : 60000, allowExecutionInForeground : true, exact : true, job: () => this.trackLocation().done(), };
BackgroundJob.register(backgroundJob);
var backgroundSchedule = { jobKey: "myJob", }
trackLocation = async() =>{
var value = await AsyncStorage.getItem('id');
var pos_lat;
var pos_lon;
var rawdate = new Date();
var date = dateFormat(rawdate,"yyyy-mm-dd HH:MM:L");
navigator.geolocation.getCurrentPosition(async(position)=>{
pos_lat=parseFloat(position.coords.latitude);
pos_lon=parseFloat(position.coords.longitude);
}
Hope it will work for you.
@Tanumay92 I have the same thing used in my project can u please send me the full coding like (trackLocation .js) file please.
[TypeError: undefined is not a function (evaluating '_this.trackLocation()')
@kameswarans i cannot post the original code or file as it is one of my client's project. Can you please explain, which type of support is needed by you??
Thanks @Tanumay92 I solved it. thnx for the reply
Hi @Tanumay92 I successfully integrated background jobs in my project and it works fine. Now i had a problem When the app is killed it shows error bug report continously that is com.facebook.react.commom.javascriptException : No Task registered for key jobname
Please Help me
@vikeri @rexlow @pewh @Tanumay92 @hkairi I,m using Background jobs for get my user location when app is killed. It works fine when app is killed it won't get location, gps status show off because of Location Mode is Battery Saving How to change it into High Accuracy it background job.
How to Change Location Mode to High Accuracy ? in background job
I try in Background job while register
navigator.geolocation.getCurrentPosition( (position) => { console.log(position); }, (error) => { console.log(error) }, {enableHighAccuracy: true, timeout: 20000, maximumAge: 10000} );
i wont work {enableHighAccuracy: true, timeout: 20000, maximumAge: 10000}
Permission
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_COURSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
React Native
"react-native": "0.55.2",
"react-native-background-job": "^2.1.1",
Please Help Me !