Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

BackgroundGeolocation is not defined

See original GitHub issue
  • Plugin version: last
  • Platform: Android
  • OS version: 6.0.0
  • Device manufacturer and model: Samsung Galaxy s7
  • Cordova version (cordova -v): 8.0.0

cordova-android-play-services-gradle-release 1.4.2 “cordova-android-play-services-gradle-release” cordova-plugin-device 2.0.2 “Device” cordova-plugin-facebook4 2.1.0 “Facebook Connect” cordova-plugin-geolocation 4.0.1 “Geolocation” cordova-plugin-googlemaps 2.3.2 “cordova-plugin-googlemaps” cordova-plugin-inappbrowser 3.0.0 “InAppBrowser” cordova-plugin-ionic-keyboard 2.1.2 “cordova-plugin-ionic-keyboard” cordova-plugin-ionic-webview 1.2.1 “cordova-plugin-ionic-webview” cordova-plugin-mauron85-background-geolocation 2.3.5 “CDVBackgroundGeolocation” cordova-plugin-request-location-accuracy 2.2.3 “Request Location Accuracy” cordova-plugin-splashscreen 5.0.2 “Splashscreen” cordova-plugin-whitelist 1.3.3 “Whitelist” cordova.plugins.diagnostic 4.0.8 “Diagnostic”

I am trying to use this plugin for IONIC1 and use the code provided in the “README” of this page. when I compile and tested on my galaxy s7, I am getting this error:


I am using this code:

app.controller(‘loginController’, function($scope,$timeout) { function onDeviceReady() { BackgroundGeolocation.configure({ locationProvider: BackgroundGeolocation.ACTIVITY_PROVIDER, desiredAccuracy: BackgroundGeolocation.HIGH_ACCURACY, stationaryRadius: 50, distanceFilter: 50, notificationTitle: ‘Background tracking’, notificationText: ‘enabled’, debug: true, interval: 10000, fastestInterval: 5000, activitiesInterval: 10000, url: ‘’, httpHeaders: { ‘X-FOO’: ‘bar’ }, // customize post properties postTemplate: { lat: ‘@latitude’, lon: ‘@longitude’, foo: ‘bar’ // you can also add your own properties } });

  BackgroundGeolocation.on('location', function(location) {
    // handle your locations here
    // to perform long running operation on iOS
    // you need to create background task
    BackgroundGeolocation.startTask(function(taskKey) {
      // execute long running task
      // eg. ajax post location
      // IMPORTANT: task has to be ended by endTask

  BackgroundGeolocation.on('stationary', function(stationaryLocation) {
    // handle stationary locations here

  BackgroundGeolocation.on('error', function(error) {
    console.log('[ERROR] BackgroundGeolocation error:', error.code, error.message);

  BackgroundGeolocation.on('start', function() {
    console.log('[INFO] BackgroundGeolocation service has been started');

  BackgroundGeolocation.on('stop', function() {
    console.log('[INFO] BackgroundGeolocation service has been stopped');

  BackgroundGeolocation.on('authorization', function(status) {
    console.log('[INFO] BackgroundGeolocation authorization status: ' + status);
    if (status !== BackgroundGeolocation.AUTHORIZED) {
      // we need to set delay or otherwise alert may not be shown
      setTimeout(function() {
        var showSettings = confirm('App requires location tracking permission. Would you like to open app settings?');
        if (showSetting) {
          return BackgroundGeolocation.showAppSettings();
      }, 1000);

  BackgroundGeolocation.on('background', function() {
    console.log('[INFO] App is in background');
    // you can also reconfigure service (changes will be applied immediately)
    BackgroundGeolocation.configure({ debug: true });

  BackgroundGeolocation.on('foreground', function() {
    console.log('[INFO] App is in foreground');
    BackgroundGeolocation.configure({ debug: false });

  BackgroundGeolocation.checkStatus(function(status) {
    console.log('[INFO] BackgroundGeolocation service is running', status.isRunning);
    console.log('[INFO] BackgroundGeolocation services enabled', status.locationServicesEnabled);
    console.log('[INFO] BackgroundGeolocation auth status: ' + status.authorization);

    // you don't need to check status before start (this is just the example)
    if (!status.isRunning) {
      BackgroundGeolocation.start(); //triggers start on start event

  // you can also just start without checking for status
  // BackgroundGeolocation.start();

  // Don't forget to remove listeners at some point!
  // {
  //   return BackgroundGeolocation.removeAllListeners(event);
  // });

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


What am I missing or what am I doing wrong? thanks

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:13 (4 by maintainers)

github_iconTop GitHub Comments

mauron85commented, Aug 22, 2018

Sorry for the confusion. Maybe it’s time to make 3.x stable.

HarelMcommented, Aug 21, 2018

I know, and I saw it, But intuitively I thought that this is intended for people using an old version and not the latest stable, i.e. I got to this repository and read this and said to myself: “hmm, this is interesting, but I’m using latest stable so this is probably not intended for me”, and continued to using it and then failing and then finding this issue…

Read more comments on GitHub >

github_iconTop Results From Across the Web

BackgroundGeolocation is not defined and Module cordova ...
In console I got: BackgroundGeolocation is not defined and Module cordova-plugin-background-geolocation.BackgroundGeolocation does not exist.
Read more >
backgroundGeolocation is not defined cordova-plugin ...
I am new in AngularJS and Ionic. I am building an app in Ionic (version 1) which will collect the GPS location of...
Read more >
[RESOLVED] BackgroundGeolocation not defined for package ...
I am able to get cordova-plugin-mauron85-background-geolocation@3.0.0-alpha.47 to work fine, the global BackgroundGeolocation is defined and ...
Read more >
[Significant Change Location Plugin] BackgroundGeolocation ...
Significant Change Location Plugin BackgroundGeolocation is not defined error. ... I keep getting the message: Can't find variable BackgroundGeolocation in ...
Read more >
BackgroundGeolocation | Cordova Background Geolocation
When the device is determined to be moving, the plugin periodically queries for geofences in proximity (eg. every minute) using the latest recorded...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found