我需要创建一个地理围栏触发器,在创建之后如果用户离开了我想调用 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
);
}