Skip to content

Instantly share code, notes, and snippets.

@Aschen
Last active June 23, 2020 04:13
Show Gist options
  • Save Aschen/729d67a6329c8dd0772c99545551433d to your computer and use it in GitHub Desktop.
Save Aschen/729d67a6329c8dd0772c99545551433d to your computer and use it in GitHub Desktop.
Geofencing precision

Kuzzle Geofencing precision

I have created a geofencing area around the Ram Manohar Lohia Hospital in New Delhi by using geojson.io.

Ram Manohar Lohia Hospital

I added two point, one inside and the other one outside the hospital but very close to geofencing zone limit (~2m).

Then I use Kuzzle realtime engine to subscribe to notification about document entering or exiting the Hospital geofencing area.

Finally I will send new documents to Kuzzle with a location corresponding to one of the two point, the program will print Document is inside or Document is outside according to the received notifications.

Try yourself

First you need to run a Kuzzle instance or your compute, follow instructions here: https://docs.kuzzle.io/core/2/guides/essentials/installing-kuzzle/

Then you need to install Kourou, the Kuzzle CLI using NPM (Node.js package manager): npm i -g kourou

Download the two scripts present in this Gist: subscribe.js and publish.js.

Subscribe to notifications in a first terminal: kourou sdk:execute < subscribe.js

Then in another terminal we are going to simulate document creation:

# trigger notification for someone entering the hospital
kourou sdk:execute -v 'pos="inside"' < publish.js

# trigger notification for someone exiting the hospital
kourou sdk:execute -v 'pos="outside"' < publish.js
const outsideHospital = {
lon: 77.2015392780304,
lat: 28.624808137823745
}
const insideHospital = {
lon: 77.20116913318634,
lat: 28.624756341501552
}
const content = {
location: pos === 'inside' ? insideHospital : outsideHospital
};
return sdk.document.createOrReplace('index', 'collection', 'doc-1', content);
const ramMahonarHospital = {
geoPolygon: {
location: {
points: [
[ 28.62777461181191, 77.20012307167053 ],
[ 28.6253449345671, 77.19834208488464 ],
[ 28.62437493143299, 77.20035910606384 ],
[ 28.62558978831039, 77.20315933227539 ],
[ 28.626343180861447, 77.20269799232483 ],
[ 28.62777461181191, 77.20012307167053 ]
]
}
}
};
return sdk.realtime.subscribe('index', 'collection', ramMahonarHospital, notif => {
if (notif.scope === 'in') {
console.log('Document is inside');
}
else {
console.log('Document is outside');
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment