While making GaymerCon we knew location search would be a priority. In all the gaymer meetups we’ve seen, awesome people who never would have found each other any other way have been brought together.
But you get tired of writing the same get_nearby_x query over and over. Wouldn’t it be nicer if there were just a mixin that could handle all that jazz? Well, enter Locatable:
And its cousin class, the Location model:
Here’s how it works:
You create the location model using Mongoid. Mongo has built-in geo-indexing and geo-search capabilities, so we make a generic class to do that.
Add the “Locatable” mixin to whatever class you want to make findable.
Anywhere in your models / controllers, you can call “get_nearby_x” on your locatable class, where x is the underscored name of any other locatable class! For example, “get_nearby_users” and “get_nearby_groups” both work for any given user or group. Neat, right?
With Locatable, you can paginate and search through any model, starting from any model, as long as you at some point input coordinates for both of them. So far, it’s proving pretty nice.