Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In Meteor DGGeofencing not working #60

Open
swapnil7434 opened this issue Sep 12, 2015 · 0 comments
Open

In Meteor DGGeofencing not working #60

swapnil7434 opened this issue Sep 12, 2015 · 0 comments

Comments

@swapnil7434
Copy link

Here is my code, it's not firing callback event.
It's register successfully on IOS. Android that also not working.
Can you please help me?

.controller('loginCtrl', ["$scope", "$stateParams", "$state", "$rootScope",
function($scope, $stateParams, $state, $rootScope) {
$scope.loginData = {};
// navigator.notification.alert('message', function() {}, '[title]', '[buttonName]');

     // gets called when region monitoring event is submitted from iOS, Android
    function processRegionMonitorCallback(result) {
        // debugger;
        var callbacktype = result.callbacktype;
        console.log(result)
        if (callbacktype == "initmonitor") {

        } else if (callbacktype == "locationupdate") {

            var fid = result.regionId;

            var new_timestamp = result.new_timestamp;
            var new_speed = result.new_speed;
            var new_course = result.new_course;
            var new_verticalAccuracy = result.new_verticalAccuracy;
            var new_horizontalAccuracy = result.new_horizontalAccuracy;
            var new_altitude = result.new_altitude;
            var new_latitude = result.new_latitude;
            var new_longitude = result.new_longitude;

            var old_timestamp = result.old_timestamp;
            var old_speed = result.old_speed;
            var old_course = result.old_course;
            var old_verticalAccuracy = result.old_verticalAccuracy;
            var old_horizontalAccuracy = result.old_horizontalAccuracy;
            var old_altitude = result.old_altitude;
            var old_latitude = result.old_latitude;
            var old_longitude = result.old_longitude;

        } else if (callbacktype == "monitorremoved") {

        } else if (callbacktype == "monitorfail") {

        } else if (callbacktype == "monitorstart") {

        } else if (callbacktype == "enter") {
        //result.callbacktype
        //result.regionId
        //result.message
        //result.timestamp
            Meteor.users.update({
                _id: result.regionId
            }, {
                $set: {
                    "profile.isCheckedIn": true
                }
            });
             $scope.$emit('refresh', Meteor.user().profile ); 
        } else if (callbacktype == "exit") {

        //result.callbacktype
        //result.regionId
        //result.message
        //result.timestamp
            Meteor.users.update({
                _id: result.regionId
            }, {
                $set: {
                    "profile.isCheckedIn": false
                }
            });
            $scope.$emit('refresh', Meteor.user().profile ); 

        }
    }

    //TODO: DO VALIDATIONS HERE..
    $scope.doLogin = function(loginForm) {
        // $state.go("app.home");
        if (!loginForm.$valid)
            return false;
        console.log($scope.loginData);
        // debugger;
        Meteor.loginWithPassword(
            $scope.loginData.email,
            $scope.loginData.password,
            function(err) {
                if (err) {
                    console.error(err);
                    alert('These credentials are not valid.');
                    // The user might not have been found, or their passwword
                    // could be incorrect. Inform the user that their
                    // login attempt has failed. 
                } else {

                    if (Meteor.user().profile.allowCheckInOut) {
                        var center = Centers.findOne({
                            '_id': Meteor.user().profile.companyCenter.toString()
                        });
                        var params = [Meteor.user()._id.toString(), center.latitude, center.longitude, "1500"];
                        console.log(params);

                        window.plugins.DGGeofencing.initCallbackForRegionMonitoring(new Array(), processRegionMonitorCallback, function(error) {
                            console.log("DGGeofencing init error");
                        });

                        window.plugins.DGGeofencing.startMonitoringRegion(params, function(result) {
                            console.log('DGGeofencing watching');
                        }, function(error) {
                            console.log("DGGeofencing failed to add region");
                        });

                        window.plugins.DGGeofencing.startMonitoringSignificantLocationChanges(
                            function(result) { 
                                console.log("Location Monitor Success: " + result);                
                            },
                            function(error) {  
                                console.log("failed to monitor location changes");   
                            }
                        );
                    }

                }
            }
        );
    }
}

]);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant