A geofence is a virtual boundary that can detect when an object enters or exits the area. This boundary can be a radius or any search area format, such as a bounding box, GeoJSON object, etc. Tile38 can turn any standard search into a geofence monitor by adding the FENCE keyword to the search.
To demonstrate, we’ll use a pubsub channel to listen for geofence notifications. Open two terminals:
In this example we use a pubsub channel.
Subscribe on the geofence pubsub channel you just created
The connection will be kept open using the SUBSCRIBE command. If any object enters or exists the 6km radius around
33.462,-112.268 the server will respond in realtime with geofence notifications.
Connect to the Tile38 server and create a point in the
fleet collection that will trigger a geofence notification
The event will appear in Terminal 1 and look like:
The server will notify the subscribed clients if the
delnotifies the client that an object has been deleted from the collection that is being fenced.
dropnotifies the client that the entire collection is dropped.
setnotifies the client that an object has been added or updated, and when it’s position is detected by the fence.
insideis when an object is inside the specified area.
outsideis when an object is outside the specified area.
enteris when an object that was not previously in the fence has entered the area.
exitis when an object that was previously in the fence has exited the area.
crossis when an object that was not previously in the fence has entered and exited the area.
By default all detect types and commands are returned.
If you would like to only have a select few then use the
DETECT option, for example:
This command will only tell the fence that you only want inside and outside detection.
It’s also possible to mask which commands are returned by using the
COMMANDS option, for example:
This specifies that you only want the enter detection for the set command.