title: Uncaught ReferenceError: backgroundGeolocation is not defined cordova-plugin-mauron85-background-geolocation
body: <p>I am new in AngularJS and Ionic. I am building an app in Ionic (version 1) which will collect the GPS location of the device in the background. I am trying to use <a href="https://github.com/mauron85/cordova-plugin-background-geolocation" rel="nofollow noreferrer">cordova-plugin-mauron85-background-geolocation</a> plugin for this purpose. But I am getting an error <code>Uncaught ReferenceError: backgroundGeolocation is not defined.</code></p>
  
  <p>My app.js</p>
  
  <pre><code>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 &amp;&amp; window.cordova.plugins &amp;&amp; window.cordova.plugins.Keyboard) {
        cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
        cordova.plugins.Keyboard.disableScroll(true);
  
      }
      if (window.StatusBar) {
        // org.apache.cordova.statusbar required
        StatusBar.styleDefault();
      }
    });
  })
  </code></pre>
  
  <p>What am I missing here?</p>