GeoFence analysis hangs at call to function

GeoFence analysis hangs at call to function

@Steven Flaxman

Hi Everyone

I think my issue is more of a script writing problem rather than a logic problem and i hope someone can help me to move forward.

I have an analysis to check if a location is within a geofence then initiate a notification.
The problem is that the script runs well till it gets to the call checkZones, here it hangs.
Here’s the call:

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

And here’s the function:

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

I would appreciate any help.
Thanks
Steven