transistorsoft / cordova-background-geolocation-lt

The most sophisticated background location-tracking & geofencing module with battery-conscious motion-detection intelligence for iOS and Android.
http://www.transistorsoft.com/shop/products/cordova-background-geolocation
Other
655 stars 277 forks source link

Entry and Exit events are not firing #238

Closed mohanchalla closed 7 years ago

mohanchalla commented 7 years ago

Your Environment

 var bgGeoConfig = {
            common: [
                { name: 'stopOnTerminate', group: 'application', value: false },
                { name: 'startOnBoot', group: 'application', value: false },
                { name: 'stopTimeout', group: 'activity recognition', value: 0 },
                { name: 'activityRecognitionInterval', group: 'activity recognition', value: 10000 },
                { name: 'debug', group: 'application', value: true },
                { name: 'deferTime', group: 'geolocation', value: 0 },
                { name: 'disableElasticity', group: 'geolocation', value: false },
                { name: 'locationTimeout', group: 'geolocation', value: 60 },
                { name: 'geofenceProximityRadius', group: 'geolocation', value: 0 },
                { name: 'geofenceInitialTriggerEntry', group: 'geolocation', value: true },
                { name: 'logLevel', group: 'geolocation', value: 5 },
                { name: 'desiredAccuracy', group: 'geolocation', value: 0 },
                { name: 'distanceFilter', group: 'application', value: 10 }
            ],
            iOS: [
                { name: 'stationaryRadius', group: 'geolocation', value: 20 },
                { name: 'activityType', group: 'geolocation', value: 'AutomotiveNavigation' }
            ],
            android: [
                { name: 'locationUpdateInterval', group: 'geolocation', value: 5000 },
                { name: 'fastestLocationUpdateInterval', group: 'geolocation', value: 1000 },
                { name: 'triggerActivities', group: 'activity recognition', value: 'running, walking, on_foot' },
                { name: 'forceReloadOnBoot', group: 'application', value: false },
                { name: 'forceReloadOnMotionChange', group: 'application', value: false },
                { name: 'forceReloadOnLocationChange', group: 'application', value: false },
                { name: 'forceReloadOnGeofence', group: 'application', value: false }
            ]
        };

Then I have created a geoLocation service and put all the method into it. on device ready I have called configure method document.addEventListener("deviceready", function () { bgGeo = window.BackgroundGeolocation; geoLocationService.configureBgGeo(); });

## Expected Behavior
<!--- Tell us what should happen -->

## Actual Behavior
<!--- Tell us what happens instead -->

Once I get the server response then I will add the locations array geoLocationService.addGeoFences(locationArray); then immedialty I am calling below 2 statements geoLocationService.startGeoFences(); geoLocationService.startBGGeoService();



## Steps to Reproduce
<!--- reproduce this issue; include code to reproduce, if relevant -->
1.
2.
3.
4.

## Context
<!--- What were you trying to do? -->

## Debug logs
<!-- include iOS / Android logs
- ios XCode logs, 
- use #getLog #emailLog methods (@see docs)
- Android: $ adb logcat
-->
christocracy commented 7 years ago

Do not use that Settings service found in the SampleApp.

var bgGeoConfig = {
            common: [
                { name: 'stopOnTerminate', group: 'application', value: false },
                { name: 'startOnBoot', group: 'application', value: false },
                { name: 'stopTimeout', group: 'activity recognition', value: 0 },
                { name: 'activityRecognitionInterval', group: 'activity recognition', value: 10000 },
                { name: 'debug', group: 'application', value: true },
                { name: 'deferTime', group: 'geolocation', value: 0 },
                { name: 'disableElasticity', group: 'geolocation', value: false },
                { name: 'locationTimeout', group: 'geolocation', value: 60 },
                { name: 'geofenceProximityRadius', group: 'geolocation', value: 0 },
                { name: 'geofenceInitialTriggerEntry', group: 'geolocation', value: true },
                { name: 'logLevel', group: 'geolocation', value: 5 },
                { name: 'desiredAccuracy', group: 'geolocation', value: 0 },
                { name: 'distanceFilter', group: 'application', value: 10 }
            ],
            iOS: [
                { name: 'stationaryRadius', group: 'geolocation', value: 20 },
                { name: 'activityType', group: 'geolocation', value: 'AutomotiveNavigation' }
            ],
            android: [
                { name: 'locationUpdateInterval', group: 'geolocation', value: 5000 },
                { name: 'fastestLocationUpdateInterval', group: 'geolocation', value: 1000 },
                { name: 'triggerActivities', group: 'activity recognition', value: 'running, walking, on_foot' },
                { name: 'forceReloadOnBoot', group: 'application', value: false },
                { name: 'forceReloadOnMotionChange', group: 'application', value: false },
                { name: 'forceReloadOnLocationChange', group: 'application', value: false },
                { name: 'forceReloadOnGeofence', group: 'application', value: false }
            ]
        };

This is in support of the Settings Screen in the Demo app only. Your app will not expose the plugin's settings to the user.

The plugin itself does not require the SettingsService found in the Demo app.

// 1. Add listeners
bgGeo.on('location', onLocation);
bgGeo.on('geofence', onGeofence);
bgGeo.on('motionchange', onMotionChange);

// 2. Configure
bgGeo.configure({
  desiredAccuracy: 0,
  distanceFilter: 50
}, function(state) {
  // 3. Add geofence.
  bgGeo.addGeofence(someGeofenceConfig);
  if (!state.enabled) {
    bgGeo.start();
  }
});
christocracy commented 7 years ago

If you want to test geofences in the SampleApp, you can add them manually by "long-press" on map. An "Add Geofence" popup will appear.

mohanchalla commented 7 years ago

No I have created it as a local variable inside my service. I am not exposing this to the user as a setting option.

mohanchalla commented 7 years ago

Ok I try to add the geofence in the sample app and I will try it.

christocracy commented 7 years ago

Whatever, don't use it. That data-structure is designed for the SampleApp. It's not meant for you to use in your own apps.

Just make a simple config object

bgGeoConfig = {
  desiredAccuracy: 0,
  distanceFilter: 50,
  .
  .
  .
};
mohanchalla commented 7 years ago

OK I will reconfigure the object and I will try once again.

christocracy commented 7 years ago

If you were sending this object to the plugin, of course it didn't work.

bgGeoConfig = {
            common: [
                { name: 'stopOnTerminate', group: 'application', value: false },
                { name: 'startOnBoot', group: 'application', value: false },
                { name: 'stopTimeout', group: 'activity recognition', value: 0 },
                { name: 'activityRecognitionInterval', group: 'activity recognition', value: 10000 },
                { name: 'debug', group: 'application', value: true },
                { name: 'deferTime', group: 'geolocation', value: 0 },
                { name: 'disableElasticity', group: 'geolocation', value: false },
                { name: 'locationTimeout', group: 'geolocation', value: 60 },
                { name: 'geofenceProximityRadius', group: 'geolocation', value: 0 },
                { name: 'geofenceInitialTriggerEntry', group: 'geolocation', value: true },
                { name: 'logLevel', group: 'geolocation', value: 5 },
                { name: 'desiredAccuracy', group: 'geolocation', value: 0 },
                { name: 'distanceFilter', group: 'application', value: 10 }
            ],
            iOS: [
                { name: 'stationaryRadius', group: 'geolocation', value: 20 },
                { name: 'activityType', group: 'geolocation', value: 'AutomotiveNavigation' }
            ],
            android: [
                { name: 'locationUpdateInterval', group: 'geolocation', value: 5000 },
                { name: 'fastestLocationUpdateInterval', group: 'geolocation', value: 1000 },
                { name: 'triggerActivities', group: 'activity recognition', value: 'running, walking, on_foot' },
                { name: 'forceReloadOnBoot', group: 'application', value: false },
                { name: 'forceReloadOnMotionChange', group: 'application', value: false },
                { name: 'forceReloadOnLocationChange', group: 'application', value: false },
                { name: 'forceReloadOnGeofence', group: 'application', value: false }
            ]
        };
bgGeo.configure(bgGeoConfig);
christocracy commented 7 years ago

See Example in this repo's README.

mohanchalla commented 7 years ago

I am iterating the object in the same way how you have done in the sample app. Based on platform dynamically I am concatenating the the array. I will reconfigure the object and check.

christocracy commented 7 years ago

Don't worry about iterating platform-specific items. That data-structure is designed for the Settings screen, for showing applicable config options in the Settings screen to the user only.

You don't need to worry about parsing out platform-specific options to the plugin itself. Each platform ignores config options that don't apply to it.

christocracy commented 7 years ago

You do not want to use anything in the Demo app's Settings system.

mohanchalla commented 7 years ago

Is it possible to add the radius of 10 for testing purpose. You have already mentioned the radius less than 100 is not accurate.

christocracy commented 7 years ago

No.

mohanchalla commented 7 years ago

Is there any co-relation between geofenceProximityRadius and addGeofence method config "radius" parameter.

christocracy commented 7 years ago

None

mohanchalla commented 7 years ago

Identifier is not allowing me to add integer string value. This value I will use for the identification purpose on my server. Ex: var geoLocation = function (obj) { this.identifier = 'Home-1'; this.radius = obj.radius; this.latitude = obj.latitude; this.longitude = obj.longitude; this.notifyOnEntry = true; this.notifyOnDwell = true; this.notifyOnExit = true; this.loiteringDelay = 10000; };

christocracy commented 7 years ago

There's nothing wrong with your identifier "Home-1"

mohanchalla commented 7 years ago

Is it possible to add only Integers as an identifier or can I use # as delimiter for my id?

christocracy commented 7 years ago

yes, but you might have to make sure it's a string.

  this.identifier = new String(123).toString()

But seriously...why not just prefix it with something?? geofence_' + id

mohanchalla commented 7 years ago

Ya fine I can use like in this way also. :)

mohanchalla commented 7 years ago

I am using the plugin for attendance marking. is DWELL event is proper for entry event?

christocracy commented 7 years ago

Dwell is Android only.

Dwell is like Entry with a delay.

mohanchalla commented 7 years ago

Because I want user should stay at least some time in the configured area then only I will mark him as present. Which event should I need to consider? Can you please help how to handle this case?

christocracy commented 7 years ago

There is no DWELL for iOS.

mohanchalla commented 7 years ago

If I close and reopen the app geofenceInitialTriggerEntry event has to fire. But it is not firing always.

christocracy commented 7 years ago

With stopOnTerminate: false, the geofences do not stop being monitored when you terminate the app.

Why should you expect the initial trigger to fire just because you terminate and reboot the app?

mohanchalla commented 7 years ago

Because If the user closes the app and once he enters into the fencing area after that If he open the app, I need to enable the SignIn button.

christocracy commented 7 years ago

I do not understand your issue. I know nothing of your "signin" button.

An initialTriggerEntry can fire only once. If the current location is within some geofence, terminating the app with stopOnTerminate: false does not stop monitoring that geofence which already fired.

This perfectly logical.

mohanchalla commented 7 years ago

I am integrating the attendance module with the plugin. If the user enters into the some location which is there with in the configured geofence. I will show "signIn" button. If he is out the the fence I will show "signout". For this If the app is closed and he opens the app with the fence then I should enable the button again. Until Unless he crosses the fences how many number of times he opens, I should always show the "signin" button.

christocracy commented 7 years ago

It's not a matter of me understanding your app (that's not my responsibility), it's up to you to build your app within the constraints of the plugin's API.

You have made a faulty assumption about the nature of geofences with stopOnTerminate: false. An entry event can fire only once (until one exits and re-enters that geofence). Terminating the app with stopOnTerminate: false does not stop monitoring the geofence whose entry event has already fired.

mohanchalla commented 7 years ago

I have already set the value as false for stopOnTerminate: false. But once I open the app it has to fire entry event? But not firing. I have even configured geofenceInitialTriggerEntry: true. And I roamed some places for exit event after that I entered into the geofence area, Opening the app It is not firing the event.

mohanchalla commented 7 years ago

If I set stopOnTerminate: true, then it is firing the event whenever he opens the app. I am sorry my assumption was wrong.