-1

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

到目前为止,我尝试了 function getFirstPositionAndTrack() { alert('单击 OK 继续获取起始位置');

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

}

4

1 回答 1

0

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

于 2015-12-07T14:42:40.353 回答