Uncaught ReferenceError: backgroundGeolocation undefined cordova-plugin-mauron85-background-geolocation

I am new to AngularJS and Ionic. I am creating an application in Ionic (version 1) that will collect the location of a GPS device in the background. I am trying to use the cordova-plugin-mauron85-background-geolocation plugin for this purpose. But I get an errorUncaught ReferenceError: backgroundGeolocation is not defined.

My app.js

angular.module('starter', ['ionic', 'starter.controllers', 'starter.services', 'firebase', 'ngMaterial'])


.factory('BackgroundGeolocationService', ['$q', '$http', function ($q, $http) {
  var callbackFn = function(location) {
      $http({
          //request options to send data to server
      });
    backgroundGeolocation.finish();
  },

  failureFn = function(error) {
    console.log('BackgroundGeoLocation error ' + JSON.stringify(error));
  },

  //Enable background geolocation
  start = function () {
      //save settings (background tracking is enabled) in local storage
    window.localStorage.setItem('bgGPS', 1);

    //...........ERROR IS ON THE FOLLOWING LINE.........    
    backgroundGeolocation.configure(callbackFn, failureFn, {
      desiredAccuracy: 10,
      stationaryRadius: 20,
      distanceFilter: 30,
      locationService: 'ANDROID_DISTANCE_FILTER',
      debug: false,
      stopOnTerminate: false
    });

    backgroundGeolocation.start();
  };

  return {
    start: start,

      // Initialize service and enable background geolocation by default
    init: function () {
      var bgGPS = window.localStorage.getItem('bgGPS');
      if (bgGPS == 1 || bgGPS == null) {
        start();
      }
    },

      // Stop data tracking
    stop: function () {
      window.localStorage.setItem('bgGPS', 0);
      backgroundGeolocation.stop();
    }
  }
}])


.run(function($ionicPlatform, BackgroundGeolocationService) {
  $ionicPlatform.ready(function() {
      BackgroundGeolocationService.init();
    // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
    // for form inputs)
    if (window.cordova && window.cordova.plugins && window.cordova.plugins.Keyboard) {
      cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
      cordova.plugins.Keyboard.disableScroll(true);

    }
    if (window.StatusBar) {
      // org.apache.cordova.statusbar required
      StatusBar.styleDefault();
    }
  });
})

What am I missing here?

+4
source share
2 answers

The plugin is open through the global namespacebackgroundGeolocation , but you refer to it as backgroundGeolocation.

: L. Javascript , .

+3

Ionic/Cordova. :

rm android

android

ionic run android --device Android. , Chrome Chome:// URL. Webview "". Chrome Dev Tools, , , ..

+1

Source: https://habr.com/ru/post/1672702/


All Articles