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({
});
backgroundGeolocation.finish();
},
failureFn = function(error) {
console.log('BackgroundGeoLocation error ' + JSON.stringify(error));
},
start = function () {
window.localStorage.setItem('bgGPS', 1);
backgroundGeolocation.configure(callbackFn, failureFn, {
desiredAccuracy: 10,
stationaryRadius: 20,
distanceFilter: 30,
locationService: 'ANDROID_DISTANCE_FILTER',
debug: false,
stopOnTerminate: false
});
backgroundGeolocation.start();
};
return {
start: start,
init: function () {
var bgGPS = window.localStorage.getItem('bgGPS');
if (bgGPS == 1 || bgGPS == null) {
start();
}
},
stop: function () {
window.localStorage.setItem('bgGPS', 0);
backgroundGeolocation.stop();
}
}
}])
.run(function($ionicPlatform, BackgroundGeolocationService) {
$ionicPlatform.ready(function() {
BackgroundGeolocationService.init();
if (window.cordova && window.cordova.plugins && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
cordova.plugins.Keyboard.disableScroll(true);
}
if (window.StatusBar) {
StatusBar.styleDefault();
}
});
})
What am I missing here?
source
share