Error TS2346: BackgroundGeolocation


#1

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();


}






    });
    }

#2

Same problem here, any idea?


#3

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) {


    }




     
    }

#4

Promise is now return byBackgroundGeolocation.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 http://stackoverflow.com/questions/39002926/ionic2-cordova-plugin for more details


#5

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


#6

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