Error TS2346: BackgroundGeolocation

Hi, what wrong with this code snippet am getting > Supplied parameters do not match any signature of call target for line : BackgroundGeolocation.configure;

initializeApp() {
    this.platform.ready().then(() => {

      StatusBar.styleDefault();
      
document.addEventListener('deviceready', onDeviceReady, false);

function onDeviceReady () {

   
    var callbackFn = function(location) {
        console.log('[js] BackgroundGeolocation callback:  ' + location.latitude + ',' + location.longitude);

        BackgroundGeolocation.finish();
    };

    var failureFn = function(error) {
        console.log('BackgroundGeolocation error');
    };

    BackgroundGeolocation.configure(callbackFn, failureFn, {
        desiredAccuracy: 10,
        stationaryRadius: 20,
        distanceFilter: 30,
        interval: 60000
    });

   
    BackgroundGeolocation.start();


}






    });
    }
1 Like

Same problem here, any idea?

Here is working one :smile:

    import { Platform } from 'ionic-angular';

    import { Injectable } from '@angular/core';

    import { Http } from '@angular/http';

    import 'rxjs/Rx';

    import { Observable } from 'rxjs/Observable';

    import { BackgroundGeolocation, Push } from 'ionic-native';



    @Injectable()

    export class Location {



      constructor(public platform: Platform, public http: Http) {



      }
     


    startTracking() {


    let config = {
     stationaryRadius: 2,
      distanceFilter: 5,
      desiredAccuracy: 10,
      debug: false,
      locationProvider: 1,
      interval: 10000,
      fastestInterval: 1000,
      activitiesInterval: 1000,
      stopOnTerminate: false,
      startOnBoot: true,
      startForeground: true,
      stopOnStillActivity: true,
      activityType: 'AutomotiveNavigation',
      syncThreshold: 100,
      saveBatteryOnBackground: true,
      maxLocations: 100,

    url: 'http://www.example.com/api/v1/geoapi' //update to the server

         };



      var callbackFn = function(location) {
// update to the server 
        };
     
        var failureFn = function(error) {
          
    alert('Network Error Check Wifi / Mobile Data');

        };

    BackgroundGeolocation.configure(callbackFn,failureFn,config);

    BackgroundGeolocation.start();


    }

    stopTracking() {


     BackgroundGeolocation.stop();

    }


    checkTracking(username) {


    }




     
    }

Promise is now return by BackgroundGeolocation.configure function… Good way to use it is:

  BackgroundGeolocation.configure(config).then((location) => {
      console.log('[js] BackgroundGeolocation callback:  ' + location.latitude + ',' + location.longitude);
      // 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((err) => console.log("BackgroundGeolocation error ", err));

See Ionic2/Cordova plugin - Stack Overflow for more details

i will try this and let you know @oliviercherrier :slight_smile:

I just made a modification (delete “plop” variable) to make it ok.