tidwall / tile38

Real-time Geospatial and Geofencing
https://tile38.com
MIT License
9.15k stars 570 forks source link

Moving geofences, or assigning a geofence to an object #17

Closed Drugantibus closed 8 years ago

Drugantibus commented 8 years ago

In our project, we need to check if two users are near to each other. How should we go about using webhooks to achieve this result? If we needed to check if a user was close to a static location, but since these are relative and moving positions...

davidxv commented 8 years ago

Hello. I've also been looking into the idea of dynamic geofencing. My approach, which works for me but may be less optimal for you, is to exploit the fact that Tile38 automatically overwrites a webhook if you give it the same name.

That means that, as (eg) Fred moves I can update a webhook named 'fred' with a standard radial geofence (to whatever radius meets the definition of 'close to') around Fred's new Point location.

Doing the same with (eg) John gives me two moving points - each of which has a geofence bubble around them. I can then set the webhook to give me the trigger return I need (eg: enter => is now close to; inside => is still close to; exit => is no longer close to; outside => is not close to; cross => became close but has since ceased to be close).

Hope that helps,

Have fun!

David.

davidxv commented 8 years ago

Ref the above:

Obviously, given that you have two geofences in motion, you have to account for double messages (one from Fred, one from John when they move close to each other) but (a) attaching the webhook to callback to an entity class (ie: Fred's geofence triggers flow to the Fred class - thereby telling Fred who is near him, etc.) gives granularity at an entity level and (b) having multiple mobile geofences gives your system - as a whole - the ability to track correlations (eg: meetings, passing/crossing routes, etc.) across different perspectives at a collective level. I do not, therefore, see double messages as a cost but, instead, as a useful bonus!

D.

tidwall commented 8 years ago

This is something that's been request by other users, and it's something I've been working on. There's still work to be done on this feature but here's an idea of what's to come.

A simple example looks like.

NEARBY people FENCE ROAM people * 100

Which will create a fence that monitors the people collection for when any object gets within 100 meters of any other object in the same collection.

Or specifically monitor an object named alice for when it's within 100 meters of any object.

NEARBY people MATCH alice FENCE ROAM people * 100

Some other examples

# Watch `alice` and `bob` for when they are within 100 meters of each other.
NEARBY people MATCH alice FENCE ROAM people bob 100
# Watch objects beginning in 'a' for when they within 100 meters of any object in the friends collection.
NEARBY people MATCH a* FENCE ROAM friends * 100

This will allow for tracking roaming positions across any collection in the database, and it works with the SETHOOK command.

I would love to hear your thoughts.

Thanks!

@davidxv, thanks a ton for providing a detailed workaround. Even though it's not optimal, it should work in the interim.

Drugantibus commented 8 years ago

That'd be exactly what we're looking for! Any ETA to the update?

davidxv commented 8 years ago

Hey Josh: That looks great. Just the sort of functionality I was aiming for - hence the workaround. Thinking it through, your forthcoming feature will greatly reduce the number of calls I have to make (and, therefore, the amount of worker the T38 server has to do in response to those).

Nice!

David

tidwall commented 8 years ago

It's fantastic to hear the excitement. I'll fast-track the feature and work towards getting a beta into the repo next week.

tidwall commented 8 years ago

I just pushed an update that follows the syntax above to 8fdc35a in the master branch.

tidwall commented 8 years ago

I'm closing this issue for now. Please let me know if you run into any problems with the roam command and feel free to open it again.