Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

background geolocation ionic 3 not updating

Background geolocation plugin for ionic isn't updating. The functionality I want is every 30 seconds ask the plugin for a lat lng value if available. The issue is, it's only giving me the values initially and then the background stops. The foreground is fine, it's really the background. Basically I'm not able to send the requests after the first initial send in the background.

gps.ts

startTracking() {   console.log("started tracking");   const config: BackgroundGeolocationConfig = {     desiredAccuracy: 10,     stationaryRadius: 20,     distanceFilter: 30,     debug: false, //  enable this hear sounds for background-geolocation life-cycle.     stopOnTerminate: false   };    this.backgroundGeolocation     .configure(config)     .subscribe((location: BackgroundGeolocationResponse) => {       this.zone.run(() => {         this.lat = location.latitude;         this.lng = location.longitude;         this.bearing = location.bearing;         this.speed = location.speed;         this.accuracy = location.accuracy;         this.timestamp = location.time;       });        this.backgroundGeolocation.finish(); // FOR IOS ONLY       this.backgroundGeolocation.stop();     });    this.backgroundGeolocation.start(); }  sendGPS() {   this.optionsService.sendGPS(gpsData).subscribe(result => {}); }  stopTracking() {   this.sendGPS(); } 

app.component.ts

constructor() {   this.sendGPSStart();   this.interval(); }  sendGPSStart() {   this.locationTracker.startTracking(); }  sendGPSStop() {   this.locationTracker.stopTracking(); }  interval() {   setInterval(() => {     this.sendGPSStart();     this.sendGPSStop();   }, "30000"); } 
like image 331
userlkjsflkdsvm Avatar asked Nov 20 '17 06:11

userlkjsflkdsvm


1 Answers

I was using the plugin and after some reading i believe the beaviour

First you need to remove the line

this.backgroundGeolocation.stop() 

from the code.

Second the background geolocation plugin due to IOS(and Android) restrictions is not executed whenever we want, but only when a 'Antena has changed event happens' So not only you need to really move as you need to connect and disconnect from carrier antennas, try applying this changes i said, turn the debug on, and go for a car ride just to test

like image 115
João Mourão Avatar answered Oct 17 '22 05:10

João Mourão