Problem with background Geolocation


#1

Hello,

I am using Background Geolocation for my app, but it doesn’t work properly, this is how i start tracking :

startTracking(idDep) {
    let counter : number = 0;
    return new Promise((resolve, reject) => {
      // Background Tracking
    
      this.diagnostic.isLocationAuthorized().then(enabled => {
        if(!enabled){
          this.diagnostic.requestLocationAuthorization().then( status => {
              console.log("Authorization status is now: "+status);
             
          }, (error) => {
              console.error(error);
              reject(false);
          });
        }

        this.locationAccuracy.canRequest().then((canRequest: boolean) => {
              
          if(canRequest) {
            // the accuracy option will be ignored by iOS
            this.locationAccuracy.request(this.locationAccuracy.REQUEST_PRIORITY_HIGH_ACCURACY).then(
              () => {
                    let config = {
                      desiredAccuracy: 0,
                      stationaryRadius: 1,
                      distanceFilter: 1,
                      notificationTitle: 'Background tracking',
                      notificationText: 'enabled',
                      debug: true,
                      stopOnTerminate: true,
                      Mode: 0
                    };
                
                    this.backgroundGeolocation.configure(config).subscribe((location) => {
                
                      console.log('BackgroundGeolocation:  ' + location.latitude + ',' + location.longitude);
                
                      // Run update inside of Angular's zone
                      this.zone.run(() => {
                        this.lat = location.latitude;
                        this.lng = location.longitude;
                        this.update_technician_location(idDep,this.lat,this.lng).then(
                          (val) => {
                            console.log("val = "+val);
                            if(!val){
                              if(this.watch != null){
                                this.backgroundGeolocation.stop();
                                this.watch.unsubscribe();
                                this.watch = null;
                              }
                            }
                          },
                          (err) => {
                            if(this.watch != null){
                              this.backgroundGeolocation.stop();
                              this.watch.unsubscribe();
                              this.watch = null;
                            }
                          }
                        );
                        
                        resolve(true);
                      });
                
                    }, (err) => {
                
                      console.log(err);
                      reject(false);
                    });
                
                    // Turn ON the background-geolocation system.
                    this.backgroundGeolocation.start();
                
                
                    //Foreground Tracking
                
                    let options = {
                    frequency: 3000,
                    enableHighAccuracy: true
                    };
                
                    this.watch = this.geolocation.watchPosition(options).filter((p: any) => p.code === undefined).subscribe((position: Geoposition) => {
                
                      console.log(position);
                  
                      // Run update inside of Angular's zone
                      this.zone.run(() => {
                        this.lat = position.coords.latitude;
                        this.lng = position.coords.longitude;
                        this.update_technician_location(idDep,this.lat,this.lng).then(
                          (val) => {
                            console.log("val = "+val);
                            if(!val){
                              if(this.watch != null){
                                this.backgroundGeolocation.stop();
                                this.watch.unsubscribe();
                                this.watch = null;
                              }
                            }
                          },
                          (err) => {
                            if(this.watch != null){
                              this.backgroundGeolocation.stop();
                              this.watch.unsubscribe();
                              this.watch = null;
                            }
                          }
                        );
                        
                        resolve(true);
                      });
                
                    });
                    
                    
              });
            }
          });
          
        });
      });
  }

i have tried many parameters on the config, but it still updates randomely, and sometimes it doesn’t update at all, is there something wrong with the plugin ? if not any solution?


#2

I am facimg the same problem .Got solution??


#3

Hello pallavibiwal,

No, i am still facing the same issue, but why did you quote requestLocationAuthorization, that parts works for me, do you have an issue in that?


#4

No
My App sends 4-5 record in background and after that it stops sending data


#5

Yes,
I have tested in 4 devices, still same, 4-5 records and stops, if i find anything i’ll let you know…


#6

yess please … I’ got frustrated now and lost all hope
:frowning: