-1

I need to create a geofence trigger , after the creation if the user Left the area i want to call 1 API after that i need to create another trigger with current(new) location info and so on

So far i tried function getFirstPositionAndTrack() { alert('Click OK to proceed to acquire starting position');

// use GPS to get the user's location
var geoPolicy = WL.Device.Geo.Profiles.LiveTracking();
geoPolicy.timeout = 60000; // set timeout to 1 minute
geoPolicy.maximumAge = 10000; // allow to use a position that is 10 seconds old

// note: to see at high-accuracy, change RoughTracking above to LiveTracking

// get the user's current position
WL.Device.Geo.acquirePosition(
        function(pos) {
            // when we receive the position, we display it and start on-going acquisition
            displayPosition(pos);


            var triggers = {
                Geo: {
                    posChange: { 
                        type: "PositionChange",
                        callback: function(deviceContext) {
                                displayPosition(deviceContext.Geo);
                            }
                    },

                    leftArea: { 
                        type: "Exit",
                        circle: {
                            longitude: pos.coords.longitude,
                            latitude: pos.coords.latitude,
                            radius: 200
                        },
                        callback: function() {
                            alert('Left the area');
                           **/* here i will call one api , And i need to create another trigger dynamically with updated position info */**
                        }
                    },

                    dwellArea: { // alert when we have stayed in the vicinity for 3 seconds
                        type: "DwellInside",
                        circle: {
                            longitude: pos.coords.longitude,
                            latitude: pos.coords.latitude,
                            radius: 50
                        },
                        dwellingTime: 3000,
                        callback: function() {
                            alert('Still in the vicinity');

                        }
                    }
                }   
            };

            WL.Device.startAcquisition({ Geo: geoPolicy }, triggers, { Geo: alertOnGeoAcquisitionErr } );
        },
        function(geoErr) {
            alertOnGeoAcquisitionErr(geoErr);
            // try again:
            getFirstPositionAndTrack();
        },
        geoPolicy
    ); 

}

MotiNK
  • 421
  • 2
  • 12
b2zswat
  • 25
  • 6

1 Answers1

0

I am assuming that you want to change the triggers that you have. You can either create a new triggers object, or update the existing one. Note that your trigger callback can receive the current device context as a parameter, which then gives you access to the current position. Then make another call to WL.Device.startAcquisition(...) again, this time passing in the new/updated triggers object.

MotiNK
  • 421
  • 2
  • 12