Query Events - GPS Nearby Loop - Taking too long

I have a truck IOT fleet that uses cameras in realtime to detect road/infrastructure damage while in motion. Events are created with GPS coordinates. I have a need for querying Events “near” a target coordinate - both for viewing results, and for determining if this “area” has been logged as damaged already (a duplicate entry). I wired these up in Losant Workflows as a test, and the problem is in querying that result.

The Workflow Event Get returns all records without regard to locality, but they could be 1000 miles away. So I run Losant Loop and then a Geolocation on them, and if it’s nearby a radius, copy and return it to the array and so on. This technically works, but is basically an N + 1 issue (for each result, run function).

The problem is that this takes 2,000 - 5,000 ms to process, and I’m still in test mode, with just 1600 sample records populated - so it won’t scale.

Is there a better way within the Losant Platform to store Events in a way that can be queried by nearby Geolocation?
Or am I better off to just store this data outside Losant?

Hey @Jason_Barbee,

What you’re looking to do would be difficult to achieve in Losant.

My suggestion would be to Google’s Big Query which supports Geospatial data.

In Losant, every time you create an event you could use the Big Query Node to insert a new row in a table with the Event ID and the GPS coordinate. Then, with the same node, query that BigQuery table to return the list of Event IDs based on coordinates.

You can checkout how to get up and running with Losant & BigQuery in this guide.

Let me know if this is something that can work for you.

Thank you,
Heath