Ionic-native: One callback in background geolocation

Created on 19 Jul 2016  路  7Comments  路  Source: ionic-team/ionic-native

Hi,

I am using the backgroundgeolocation on a ts page but the succes callback is only fired once. Can somebody tell me what the reason is for this problem?

ionic native: 3.3.7

ionic info output:
Cordova CLI: 6.2.0
Ionic Framework Version: 2.0.0-beta.10
Ionic CLI Version: 2.0.0-beta.32
Ionic App Lib Version: 2.0.0-beta.18
OS: Distributor ID: Ubuntu Description: Ubuntu 14.04.3 LTS
Node Version: v5.6.0

bug

Most helpful comment

Thanks for your reply! That was the same thing I thought :) , When do you think this problem is solved?

All 7 comments

this.platform.ready().then(() => {
BackgroundGeolocation.deleteAllLocations();
BackgroundGeolocation.configure(config)
  .then((location) => {
    // Fired only once
    this.addNewLocation(location);
    // IMPORTANT:  You must execute the finish method here to inform the native plugin that you're finished,
    // and the background-task may be completed.  You must do this regardless if your HTTP request is successful or not.
    // IF YOU DON'T, ios will CRASH YOUR APP for spending too much time in the background.
    // BackgroundGeolocation.finish(); // FOR IOS ONLY
  })
  .catch((error) => {
    console.log('BackgroundGeolocation error');
  });

// Turn ON the background-geolocation system.  The user will be tracked whenever they suspend the app.
BackgroundGeolocation.start().then(log => {
  console.log(log);
});
});

Might be because they return promises, they should return Observables instead.

Thanks for your reply! That was the same thing I thought :) , When do you think this problem is solved?

Changing this to be a sync since it's a non-standard behavior

@pascalrijk can you try the code in master now? Just pushed a fix that changes the semantics to be this:

BackgroundGeolocation.configure((pos) => {
}, (err) => {
}, { // options ))

Also updated the config to match the most recent version of the plugin

@mlynch: It works, thank you!

Steps to update from master:

  1. Download master
  2. Copy master to node_modules/ionic-native
  3. cd node_modules/ionic-native
  4. npm install
  5. npm run build
  6. Configure BackgroundGeolocation:
BackgroundGeolocation.configure((location) => {
  console.log('Geolocation: ' + location.latitude + ',' + location.longitude + ', ' + location.speed);
  BackgroundGeolocation.finish();
}, (error) => {
  console.log('BackgroundGeolocation error', error);
}, config);

7 . ionic serve and run

An easier way to install from master:

npm install git+https://github.com/driftyco/ionic-native.git

Was this page helpful?
0 / 5 - 0 ratings

Related issues

goleary picture goleary  路  3Comments

wwallace picture wwallace  路  4Comments

mateo666 picture mateo666  路  3Comments

icchio picture icchio  路  3Comments

lycwed picture lycwed  路  4Comments