Geofencing

Geofence animation 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:

Terminal 1

Connect to the Tile38 server and create the geofence using the SETCHAN or SETHOOK command.

In this example we use a pubsub channel.

$ tile38-cli localhost:9851> SETCHAN warehouse NEARBY fleet FENCE POINT 33.462 -112.268 6000 {"ok":true,"elapsed":"21.712µs"}

Subscribe on the geofence pubsub channel you just created

localhost:9851> SUBSCRIBE warehouse {"ok":true,"command":"subscribe","channel":"warehouse","num":1,"elapsed":"7.361µs"}

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.

Terminal 2

Connect to the Tile38 server and create a point in the fleet collection that will trigger a geofence notification

$ tile38-cli localhost:9851> SET fleet bus POINT 33.460 -112.260 {"ok":true,"elapsed":"12.988µs"}

The event will appear in Terminal 1 and look like:

{ "command":"set", "group":"5c5203ccf5ec4e4f349fd038", "detect":"inside", "hook":"warehouse", "key":"fleet", "time":"2019-01-30T13:06:36.769273-07:00", "id":"bus", "object":{"type":"Point","coordinates":[-112.26,33.46]} }

The server will notify the subscribed clients if the command is del or set or drop.

The detect may be one of the following values.

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:

SETCHAN warehouse NEARBY fleet FENCE DETECT inside,outside POINT 33.462 -112.268 6000

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:

SETCHAN warehouse NEARBY fleet FENCE DETECT enter COMMANDS set POINT 33.462 -112.268 6000

This specifies that you only want the enter detection for the set command.