Cordova Geofence Plugin


I have a problem and hope some can give me some insight on what I’m doing wrong.

I start with a blank Ionic tabs app and then add the Cordova geofence plugin ( via cordova plugin add cordova-plugin-geofence
Inside my app.js I try to initialize it via

$ionicPlatform.ready(function () {

But this doesn’t work. In my browser console it says: “window.geofence is undefined”.

I’ve seen the ionic sample app but found it not really helpful as the app is quite complex already. I want to recreate this step by step in order to improve my skills.

Any help would be appreciated.


Anyone able to help me and shine some light on this? Thank you.

Of course, it’s not working.


document.addEventListener('deviceready', function () {
    // window.geofence is now available
}, false);

instead of:

$ionicPlatform.ready(function () {

ionic.Platform.ready is not Cordova deviceready.

Thank you for your help. But this didn’t work.

I have tried the following… but still I get the error that window.geofence is undefined… I don’t think it has something to do with how the method is called. Even with the 10 seconds timeout I can catch the console output but still get the undefined error.

.run(function($ionicPlatform) {

  document.addEventListener('deviceready', function () {
      // window.geofence is now available
  }, false);

  setTimeout(function() {
  }, 10000);

  $ionicPlatform.ready(function() {

I’m getting a bit desperate here… has anybody an idea, how to get this plugin working?

Maybe it only works on a device, not under “ionic serve”. I’m also going to evaluate this geofence stuff.

I’m not sure… I tried it with the Ionic view app. But I also tried their Iionic example app and it also didn’t work.

Ionic View doesn’t contain all Cordova plugins so I can imagine it doesn’t work. I think you need to do “ionic build” or “ionic run” with a real device.

Used Ionic run with the sample app but still no luck… it stops at “Obtaining location”.

Okay, I did some more diggiing and experience really strange behaviour:

I tested both the plugins and

I can’t get them to work them when I’m using an Ionic workflow but I can get them to work using a Cordova workflow

What I Do:

  • Create an Ionic app with $ionic start geotest
  • Install one of the plugins as described on their github repo
  • when I try to initialize them, I get the error described in my first post, that the object is undefined

When using a Cordova workflow (cordova create geotest and installing one the pf the plugins as described on their repo I can access the object and everything seems to work fine).

Can somebody tell me what I’m doing wrong here? I never experienced this behaviour before with other plugins.

Update to the latest cordova and ionic

sudo npm install -g ionic cordova