Skip to content

Repository files navigation

GeoQuery

Saves you the hassle of writing your own location queries and uses pre-built and reusable methods.

The current version only supports Rails 4.2+. Request other versions by opening an issue.

##Install These instructions already assume you have postgis enabled on your database, please follow the instructions here to enabled it https://github.com/rgeo/activerecord-postgis-adapter#install

Include gem

gem'geo_query'

Generate the migration

Will add a geography field to your model (Skip if already exists)

# Where user is your model namerailsggeo_query:resourceUser

Attach the helper to your model

classUser < ActiveRecord::Base# location column defaults to :coordinatesgeo_queryablecolumn: :coordinatesend

##Usage The helper gives your model the following methods

Instance Methods

# Returns nearest objectsobject.near(radius)

Class Methods

# Returns all objects within the specified radius ordered by nearestClass.near_lat_lon(lat,lon,radius)#radius defaults to 500metres
# Returns all objects within a rectangleClass.within_bounding_box(min_lat,min_lon,max_lat,max_lon)

Attribute setters

User.create(lat: -38,lon: 144)

More coming soon...

About

Saves you the hassle of writing your own location queries and uses pre-built and reusable methods.

Resources

Stars

2 stars

Watchers

11 watching

Forks

Releases

Packages

Contributors

Languages