Skip to content

Instantly share code, notes, and snippets.

@jonathanKingston
Created April 30, 2012 14:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonathanKingston/2558822 to your computer and use it in GitHub Desktop.
Save jonathanKingston/2558822 to your computer and use it in GitHub Desktop.
find nearbythings
Meteor.setInterval(function() {
var allTheThings = Things.find({});
//Near will contain all the object _id's and this will be an array of all other objects nearby.
near = {}
allTheThings.forEach(function (thing) {
if (thing != undefined) {
near[thing._id] = [];
allTheThings.forEach(function (thing2) {
if(thing2.x >= thing.x-5 && thing2.x <= thing.x+5) {
if(thing2.y >= thing.y-5 && thing2.y <= thing.y+5) {
near[thing._id].push thing2;
}
}
});
}
}
},5000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment