From c950a8105aa54725575f6216de7c7a84b67d170e Mon Sep 17 00:00:00 2001 From: Isaac Norman Date: Wed, 17 Jun 2015 16:45:22 +1000 Subject: [PATCH 1/2] Changed the name of within_bounding_box to within_geo_query_bounding_box to stop compatibility issues with the standard geocoder gem --- README.md | 2 +- lib/geo_query/geo_queryable.rb | 4 ++-- spec/models/user_spec.rb | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index c8b9d93..ad0d490 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ Class.near_lat_lon(lat, lon, radius) #radius defaults to 500metres ``` ```ruby # Returns all objects within a rectangle -Class.within_bounding_box(min_lat, min_lon, max_lat, max_lon) +Class.within_geo_query_bounding_box(min_lat, min_lon, max_lat, max_lon) ``` **Attribute setters** ```ruby diff --git a/lib/geo_query/geo_queryable.rb b/lib/geo_query/geo_queryable.rb index 2c41cd5..a2c9735 100644 --- a/lib/geo_query/geo_queryable.rb +++ b/lib/geo_query/geo_queryable.rb @@ -53,7 +53,7 @@ def self.near_lat_lon(lat, lon, radius=500) #radius in metres end ## Returns all objects within a bounding box - def self.within_bounding_box(min_lat, min_lon, max_lat, max_lon) + def self.within_geo_query_bounding_box(min_lat, min_lon, max_lat, max_lon) select("#{self.table_name}.*"). where("#{self.table_name}.#{self.point_column} && ST_MakeEnvelope(?, ?, ?, ?, 4326)", min_lon, min_lat, max_lon, max_lat) @@ -78,4 +78,4 @@ def geo_queryable(options = {}) end end end -end \ No newline at end of file +end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 7d157af..53910ea 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -65,16 +65,16 @@ end end - describe "self.within_bounding_box" do + describe "self.within_geo_query_bounding_box" do it "returns user within bounding box" do user = create(:user, lat: 37.8117802, lon: 144.9651743) - expect(User.within_bounding_box(37.8117802, 144.9651743, 37.8117802, 144.9651743)).to include user + expect(User.within_geo_query_bounding_box(37.8117802, 144.9651743, 37.8117802, 144.9651743)).to include user end it "doesn't return user outside bounding box" do user = create(:user, lat: -37.8142383, lon: 144.9656678) - expect(User.within_bounding_box(37.8117802, 144.9651743, 37.8117802, 144.9651743)).to_not include user + expect(User.within_geo_query_bounding_box(37.8117802, 144.9651743, 37.8117802, 144.9651743)).to_not include user end end From 8cb11071b33be5a7fcd5bc2d14d285adaaba3961 Mon Sep 17 00:00:00 2001 From: Isaac Norman Date: Mon, 15 Feb 2016 16:08:43 +1100 Subject: [PATCH 2/2] Update readme to reflect changes --- README.md | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index ad0d490..d72367e 100644 --- a/README.md +++ b/README.md @@ -4,13 +4,21 @@ Saves you the hassle of writing your own location queries and uses pre-built and The current version only supports Rails **4.2+**. Request other versions by opening an issue. +### Release Notes for 0.2.0 + +This update changes the `within_bounding_box` method to `within_geo_query_bounding_box` in order to be compatible with the [Geocoder gem](https://github.com/alexreisner/geocoder). If you are updating to version `0.2.0` please remember to change method calls to new syntax + ##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* + +**NOTE:** These instructions already assume you have postgis enabled on your database. + +If you do not have postgis enabled please follow the instructions [here]( https://github.com/rgeo/activerecord-postgis-adapter#install*) to enabled it.* **Include gem** ```ruby gem 'geo_query' ``` + **Generate the migration** *Will add a geography field to your model (Skip if already exists)* @@ -18,6 +26,7 @@ gem 'geo_query' # Where user is your model name rails g geo_query:resource User ``` + **Attach the helper to your model** ```ruby class User < ActiveRecord::Base @@ -32,17 +41,19 @@ The helper gives your model the following methods **Instance Methods** ```ruby # Returns nearest objects -object.near(radius) +object.near(radius) #in metres ``` + **Class Methods** ```ruby # Returns all objects within the specified radius ordered by nearest -Class.near_lat_lon(lat, lon, radius) #radius defaults to 500metres +Class.near_lat_lon(lat, lon, radius) #in metres, defaults to 500 ``` ```ruby # Returns all objects within a rectangle Class.within_geo_query_bounding_box(min_lat, min_lon, max_lat, max_lon) ``` + **Attribute setters** ```ruby User.create(lat: -38, lon: 144)