Worklight Geo fencing动态更新触发器位置

时间:2015-12-06 13:59:20

标签: ibm-mobilefirst geofencing worklight-studio worklight-geolocation

我需要创建一个地理围栏触发器,在创建之后如果用户离开我要调用1 API的区域,之后我需要创建另一个带有当前(新)位置信息的触发器等等

到目前为止,我试过了     function getFirstPositionAndTrack(){     警报('单击确定以继续获取起始位置');

// 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
    ); 

}

1 个答案:

答案 0 :(得分:0)

我假设您想要更改您拥有的触发器。您可以创建新的触发器对象,也可以更新现有的触发器对象。请注意,您的触发器回调可以接收current device context作为参数,然后可以访问当前位置。然后再次调用WL.Device.startAcquisition(...),这次传入新的/更新的触发器对象。