微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

脚本在调用函数时失败

如何解决脚本在调用函数时失败

请有人帮我写脚本。它在调用函数时失败,我不知道为什么。

这是我设置参数并调用函数 checkZone

// 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 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?