如何解决脚本在调用函数时失败
// Get the geofence Meta data and put it into a list
const zones = geofence.map((geofence) => geofence.Metadata);
const geofence_list = zones[0];
context.log("geofence_list = ",zones[0]);
// Split location into lat long for point
const latlong = location[0].value.split(",");
//context.log("lat =",latlong[0]);
//context.log("long =",latlong[1]);
const point = [latlong[1],latlong[0]];
context.log("point =",point);
//Call the function insideZones to see if the device is in a geofence or not
const insideZones = await checkZones(point,geofence_list);
这是功能
// This function checks if our device is inside any geofence
async function checkZones(point,geofence_list) {
context.log('Running checkzones');
const insideZones = [];
// The line below gets all polygon geofences that we may have.
const polygons = geofence_list.filter((x) => x.geolocation.type === "polygon");
if (polygons.length) {
// Here we check if our device is inside any polygon geofence using our function above.
for (const polygon of polygons) {
if (insidepolygon(point,polygon.geolocation.coordinates[0])){
insideZones.push(polygon.event);
}
}
}
// The line below gets all Point (circle) geofences that we may have.
const circles = geofence_list.filter((x) => x.geolocation.type === "Point");
if (circles.length) {
// Here we check if our device is inside any Point geofence using a third party library called geolib.
for (const circle of circles) {
if (geolib.isPointWithinRadius
({latitude:point[1],longitude: point[0] },{latitude: circle.geolocation.coordinates[0],longitude: circle.geolocation.coordinates[1] },circle.geolocation.radius)) {
insideZones.push(circle.event);
}
}
}
return insideZones;
}
将“geofence_list =”打印到控制台。 将“point =”打印到控制台。 不打印“运行检查区”。
控制台输出
[2021-02-05 14:24:31] The geofence is : inside_geo
[2021-02-05 14:24:31] {}
[2021-02-05 14:24:31] point = 18.3851121,-34.1258163
[2021-02-05 14:24:31] geofence_list = {"color":"","event":"entering_zone","geolocation":{"coordinates":[-34.12429447233787,18.38298082351685],"radius":429.8821561214525,"type":"Point"},"id":"prUirTWSm"}
[2021-02-05 14:24:31] The location is: -34.1258163,18.3851121
[2021-02-05 14:24:31] Running Analysis
[2021-02-05 14:24:31] Enviroment Set
[2021-02-05 14:24:31] Starting analysis 601a99a566fd8200113fdcad
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。