acts_as_geocodable 2.0.2 → 2.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.textile +129 -0
- data/lib/acts_as_geocodable.rb +7 -2
- data/lib/acts_as_geocodable/version.rb +1 -1
- metadata +10 -117
- data/README +0 -98
data/README.textile
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
h1. acts_as_geocodable
|
2
|
+
|
3
|
+
acts_as_geocodable helps you build geo-aware applications. It automatically geocodes your models when they are saved, giving you the ability to search by location and calculate distances between records.
|
4
|
+
|
5
|
+
*Beginning with version 2, we require Rails 3. Use one of the 1.0.x tags to work with Rails 2.3.*
|
6
|
+
|
7
|
+
We've adopted the ARel style syntax for finding records.
|
8
|
+
|
9
|
+
h2. Usage
|
10
|
+
|
11
|
+
<pre><code>event = Event.create :street => "777 NE Martin Luther King, Jr. Blvd.",
|
12
|
+
:locality => "Portland", :region => "Oregon", :postal_code => 97232
|
13
|
+
|
14
|
+
event.geocode.latitude #=> 45.529100000000
|
15
|
+
event.geocode.longitude #=> -122.644200000000
|
16
|
+
|
17
|
+
event.distance_to "49423" #=> 1807.66560483205
|
18
|
+
|
19
|
+
Event.origin("97232", :within => 50)
|
20
|
+
|
21
|
+
Event.origin("Portland, OR").nearest</code></pre>
|
22
|
+
|
23
|
+
h2. Installation
|
24
|
+
|
25
|
+
Install as a gem
|
26
|
+
|
27
|
+
<pre><code>gem install acts_as_geocodable</code></pre>
|
28
|
+
|
29
|
+
or add it to your Gemfile
|
30
|
+
|
31
|
+
<pre><code>gem 'acts_as_geocodable'</code></pre>
|
32
|
+
|
33
|
+
"Graticule":http://github.com/collectiveidea/graticule is used for all the heavy lifting and will be installed too.
|
34
|
+
|
35
|
+
h2. Upgrading
|
36
|
+
|
37
|
+
Before October 2008, precision wasn't included in the @Geocode@ model. Make sure you add a string precision column to your geocode table if you're upgrading from an older version, and update Graticule.
|
38
|
+
|
39
|
+
Also, if you're upgrading from a previous version of this plugin, note that @:city@ has been renamed to @:locality@ to be consistent with Graticule 0.2. Create a migration that has:
|
40
|
+
|
41
|
+
<pre><code>rename_column :geocodes, :city, :locality</code></pre>
|
42
|
+
|
43
|
+
Also remember to change your mapping in your geocodable classes to use the @:locality@ key instead of @:city@:
|
44
|
+
|
45
|
+
<pre><code>class Event < ActiveRecord::Base
|
46
|
+
acts_as_geocodable :address => {:street => :address1, :locality => :city,
|
47
|
+
:region => :state, :postal_code => :zip}
|
48
|
+
end</code></pre>
|
49
|
+
|
50
|
+
h2. Configuration
|
51
|
+
|
52
|
+
Create the required tables
|
53
|
+
|
54
|
+
<pre><code>rails generate acts_as_geocodable
|
55
|
+
rake db:migrate</code></pre>
|
56
|
+
|
57
|
+
Set the default geocoder in your environment.rb file.
|
58
|
+
|
59
|
+
<pre><code>Geocode.geocoder = Graticule.service(:yahoo).new 'your_api_key'</code></pre>
|
60
|
+
|
61
|
+
Then, in each model you want to make geocodable, add @acts_as_geocodable@.
|
62
|
+
|
63
|
+
<pre><code>class Event < ActiveRecord::Base
|
64
|
+
acts_as_geocodable
|
65
|
+
end</code></pre>
|
66
|
+
|
67
|
+
The only requirement is that your model must have address fields. By default, acts_as_geocodable looks for attributes called +street+, +locality+, +region+, +postal_code+, and +country+. To change these, you can provide a mapping in the @:address@ option:
|
68
|
+
|
69
|
+
<pre><code>class Event < ActiveRecord::Base
|
70
|
+
acts_as_geocodable :address => {:street => :address1, :locality => :city, :region => :state, :postal_code => :zip}
|
71
|
+
end</code></pre>
|
72
|
+
|
73
|
+
If that doesn't meet your needs, simply override the default @to_location@ method in your model, and return a @Graticule::Location@ with those attributes set.
|
74
|
+
|
75
|
+
acts_as_geocodable can also update your address fields with the data returned from the geocoding service:
|
76
|
+
|
77
|
+
<pre><code>class Event < ActiveRecord::Base
|
78
|
+
acts_as_geocodable :normalize_address => true
|
79
|
+
end</code></pre>
|
80
|
+
|
81
|
+
h2. IP-based Geocoding
|
82
|
+
|
83
|
+
acts_as_geocodable adds a @remote_location@ method in your controllers that uses http://hostip.info to guess remote users location based on their IP address.
|
84
|
+
|
85
|
+
<pre><code>def index
|
86
|
+
@nearest = Store.origin(remote_location).nearest if remote_location
|
87
|
+
@stores = Store.all
|
88
|
+
end</code></pre>
|
89
|
+
|
90
|
+
Keep in mind that IP-based geocoding is not always accurate, and often will not return any results.
|
91
|
+
|
92
|
+
h2. Contributing
|
93
|
+
|
94
|
+
In the spirit of "free software":http://www.fsf.org/licensing/essays/free-sw.html, **everyone** is encouraged to help improve this project.
|
95
|
+
|
96
|
+
Here are some ways *you* can contribute:
|
97
|
+
|
98
|
+
* using alpha, beta, and prerelease versions
|
99
|
+
* reporting bugs
|
100
|
+
* suggesting new features
|
101
|
+
* writing or editing documentation
|
102
|
+
* writing specifications
|
103
|
+
* writing code (**no patch is too small**: fix typos, add comments, clean up inconsistent whitespace)
|
104
|
+
* refactoring code
|
105
|
+
* closing "issues":https://github.com/collectiveidea/acts_as_geocodable/issues/
|
106
|
+
* reviewing patches
|
107
|
+
|
108
|
+
h2. Submitting an Issue
|
109
|
+
|
110
|
+
We use the "GitHub issue tracker":https://github.com/collectiveidea/acts_as_geocodable/issues/ to track bugs
|
111
|
+
and features. Before submitting a bug report or feature request, check to make sure it hasn't already
|
112
|
+
been submitted. You can indicate support for an existing issuse by voting it up. When submitting a
|
113
|
+
bug report, please include a "Gist":https://gist.github.com/ that includes a stack trace and any
|
114
|
+
details that may be necessary to reproduce the bug, including your gem version, Ruby version, and
|
115
|
+
operating system. Ideally, a bug report should include a pull request with failing specs.
|
116
|
+
|
117
|
+
h2. Submitting a Pull Request
|
118
|
+
|
119
|
+
1. Fork the project.
|
120
|
+
2. Create a topic branch.
|
121
|
+
3. Implement your feature or bug fix.
|
122
|
+
4. Add specs for your feature or bug fix.
|
123
|
+
5. Run @bundle exec rake@. If your changes are not 100% covered and passing, go back to step 4.
|
124
|
+
6. Commit and push your changes.
|
125
|
+
7. Submit a pull request. Please do not include changes to the gemspec, version, or history file. (If you want to create your own version for some reason, please do so in a separate commit.)
|
126
|
+
|
127
|
+
h3. To Do
|
128
|
+
|
129
|
+
* configurable formulas
|
data/lib/acts_as_geocodable.rb
CHANGED
@@ -37,8 +37,13 @@ module ActsAsGeocodable #:nodoc:
|
|
37
37
|
:units => :miles
|
38
38
|
}.merge(options)
|
39
39
|
|
40
|
-
|
41
|
-
|
40
|
+
if ActiveRecord::VERSION::MAJOR >= 3
|
41
|
+
class_attribute :acts_as_geocodable_options
|
42
|
+
self.acts_as_geocodable_options = options
|
43
|
+
else
|
44
|
+
write_inheritable_attribute :acts_as_geocodable_options, options
|
45
|
+
class_inheritable_reader :acts_as_geocodable_options
|
46
|
+
end
|
42
47
|
|
43
48
|
define_callbacks :geocoding
|
44
49
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: acts_as_geocodable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 9
|
5
|
+
prerelease:
|
6
6
|
segments:
|
7
7
|
- 2
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 2.0.
|
9
|
+
- 3
|
10
|
+
version: 2.0.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Daniel Morrison
|
@@ -17,8 +17,7 @@ autorequire:
|
|
17
17
|
bindir: bin
|
18
18
|
cert_chain: []
|
19
19
|
|
20
|
-
date: 2011-
|
21
|
-
default_executable:
|
20
|
+
date: 2011-11-15 00:00:00 Z
|
22
21
|
dependencies:
|
23
22
|
- !ruby/object:Gem::Dependency
|
24
23
|
version_requirements: &id001 !ruby/object:Gem::Requirement
|
@@ -34,121 +33,16 @@ dependencies:
|
|
34
33
|
version: 2.0.0
|
35
34
|
requirement: *id001
|
36
35
|
type: :runtime
|
37
|
-
name: graticule
|
38
|
-
prerelease: false
|
39
|
-
- !ruby/object:Gem::Dependency
|
40
|
-
version_requirements: &id002 !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
|
-
requirements:
|
43
|
-
- - ">="
|
44
|
-
- !ruby/object:Gem::Version
|
45
|
-
hash: 3
|
46
|
-
segments:
|
47
|
-
- 0
|
48
|
-
version: "0"
|
49
|
-
requirement: *id002
|
50
|
-
type: :development
|
51
|
-
name: rails
|
52
|
-
prerelease: false
|
53
|
-
- !ruby/object:Gem::Dependency
|
54
|
-
version_requirements: &id003 !ruby/object:Gem::Requirement
|
55
|
-
none: false
|
56
|
-
requirements:
|
57
|
-
- - "="
|
58
|
-
- !ruby/object:Gem::Version
|
59
|
-
hash: 21
|
60
|
-
segments:
|
61
|
-
- 1
|
62
|
-
- 2
|
63
|
-
- 5
|
64
|
-
version: 1.2.5
|
65
|
-
requirement: *id003
|
66
|
-
type: :development
|
67
|
-
name: sqlite3-ruby
|
68
|
-
prerelease: false
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
version_requirements: &id004 !ruby/object:Gem::Requirement
|
71
|
-
none: false
|
72
|
-
requirements:
|
73
|
-
- - "="
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
hash: 45
|
76
|
-
segments:
|
77
|
-
- 2
|
78
|
-
- 8
|
79
|
-
- 1
|
80
|
-
version: 2.8.1
|
81
|
-
requirement: *id004
|
82
|
-
type: :development
|
83
|
-
name: mysql
|
84
|
-
prerelease: false
|
85
|
-
- !ruby/object:Gem::Dependency
|
86
|
-
version_requirements: &id005 !ruby/object:Gem::Requirement
|
87
|
-
none: false
|
88
|
-
requirements:
|
89
|
-
- - ~>
|
90
|
-
- !ruby/object:Gem::Version
|
91
|
-
hash: 31098209
|
92
|
-
segments:
|
93
|
-
- 2
|
94
|
-
- 0
|
95
|
-
- 0
|
96
|
-
- beta
|
97
|
-
version: 2.0.0.beta
|
98
|
-
requirement: *id005
|
99
|
-
type: :development
|
100
|
-
name: rspec
|
101
|
-
prerelease: false
|
102
|
-
- !ruby/object:Gem::Dependency
|
103
|
-
version_requirements: &id006 !ruby/object:Gem::Requirement
|
104
|
-
none: false
|
105
|
-
requirements:
|
106
|
-
- - ">="
|
107
|
-
- !ruby/object:Gem::Version
|
108
|
-
hash: 3
|
109
|
-
segments:
|
110
|
-
- 0
|
111
|
-
version: "0"
|
112
|
-
requirement: *id006
|
113
|
-
type: :development
|
114
|
-
name: factory_girl
|
115
|
-
prerelease: false
|
116
|
-
- !ruby/object:Gem::Dependency
|
117
|
-
version_requirements: &id007 !ruby/object:Gem::Requirement
|
118
|
-
none: false
|
119
|
-
requirements:
|
120
|
-
- - ">="
|
121
|
-
- !ruby/object:Gem::Version
|
122
|
-
hash: 3
|
123
|
-
segments:
|
124
|
-
- 0
|
125
|
-
version: "0"
|
126
|
-
requirement: *id007
|
127
|
-
type: :development
|
128
|
-
name: database_cleaner
|
129
|
-
prerelease: false
|
130
|
-
- !ruby/object:Gem::Dependency
|
131
|
-
version_requirements: &id008 !ruby/object:Gem::Requirement
|
132
|
-
none: false
|
133
|
-
requirements:
|
134
|
-
- - ">="
|
135
|
-
- !ruby/object:Gem::Version
|
136
|
-
hash: 3
|
137
|
-
segments:
|
138
|
-
- 0
|
139
|
-
version: "0"
|
140
|
-
requirement: *id008
|
141
|
-
type: :development
|
142
|
-
name: ruby-debug
|
143
36
|
prerelease: false
|
37
|
+
name: graticule
|
144
38
|
description: Simple geocoding for Rails ActiveRecord models. See the README for more details.
|
145
39
|
email: info@collectiveidea.com
|
146
40
|
executables: []
|
147
41
|
|
148
42
|
extensions: []
|
149
43
|
|
150
|
-
extra_rdoc_files:
|
151
|
-
|
44
|
+
extra_rdoc_files: []
|
45
|
+
|
152
46
|
files:
|
153
47
|
- lib/acts_as_geocodable/geocode.rb
|
154
48
|
- lib/acts_as_geocodable/geocoding.rb
|
@@ -160,8 +54,7 @@ files:
|
|
160
54
|
- lib/generators/acts_as_geocodable/USAGE
|
161
55
|
- CHANGELOG
|
162
56
|
- MIT-LICENSE
|
163
|
-
- README
|
164
|
-
has_rdoc: true
|
57
|
+
- README.textile
|
165
58
|
homepage: http://github.com/collectiveidea/acts_as_geocodable
|
166
59
|
licenses: []
|
167
60
|
|
@@ -191,7 +84,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
191
84
|
requirements: []
|
192
85
|
|
193
86
|
rubyforge_project:
|
194
|
-
rubygems_version: 1.
|
87
|
+
rubygems_version: 1.8.10
|
195
88
|
signing_key:
|
196
89
|
specification_version: 3
|
197
90
|
summary: Simple geocoding for Rails ActiveRecord models
|
data/README
DELETED
@@ -1,98 +0,0 @@
|
|
1
|
-
= acts_as_geocodable
|
2
|
-
|
3
|
-
acts_as_geocodable helps you build geo-aware applications. It automatically geocodes your models when they are saved, giving you the ability to search by location and calculate distances between records.
|
4
|
-
|
5
|
-
Beginning with version 2, we require Rails 3. Use one of the 1.0.x tags to work with Rails 2.3.
|
6
|
-
|
7
|
-
Also, we've adopted the ARel style syntax for finding records.
|
8
|
-
|
9
|
-
== Usage
|
10
|
-
|
11
|
-
event = Event.create :street => "777 NE Martin Luther King, Jr. Blvd.",
|
12
|
-
:locality => "Portland", :region => "Oregon", :postal_code => 97232
|
13
|
-
|
14
|
-
event.geocode.latitude #=> 45.529100000000
|
15
|
-
event.geocode.longitude #=> -122.644200000000
|
16
|
-
|
17
|
-
event.distance_to "49423" #=> 1807.66560483205
|
18
|
-
|
19
|
-
Event.origin("97232", :within => 50)
|
20
|
-
|
21
|
-
Event.origin("Portland, OR").nearest
|
22
|
-
|
23
|
-
== Installation
|
24
|
-
|
25
|
-
Install as a gem
|
26
|
-
|
27
|
-
gem install acts_as_geocodable
|
28
|
-
|
29
|
-
Graticule[link:http://rubyforge.org/projects/graticule] is used for all the heavy lifting and will be installed too.
|
30
|
-
|
31
|
-
== Upgrading
|
32
|
-
|
33
|
-
Before October 2008, precision wasn't included in the Geocode model. Make sure you add a string precision column to your geocode table if you're upgrading from an older version, and update Graticule.
|
34
|
-
|
35
|
-
Also, if you're upgrading from a previous version of this plugin, note that :city has been renamed to :locality to be consistent with Graticule 0.2. Create a migration that has:
|
36
|
-
|
37
|
-
rename_column :geocodes, :city, :locality
|
38
|
-
|
39
|
-
Also remember to change your mapping in your geocodable classes to use the :locality key instead of :city:
|
40
|
-
|
41
|
-
class Event < ActiveRecord::Base
|
42
|
-
acts_as_geocodable :address => {:street => :address1, :locality => :city,
|
43
|
-
:region => :state, :postal_code => :zip}
|
44
|
-
end
|
45
|
-
|
46
|
-
== Configuration
|
47
|
-
|
48
|
-
Create the required tables
|
49
|
-
|
50
|
-
rails generate acts_as_geocodable
|
51
|
-
rake db:migrate
|
52
|
-
|
53
|
-
Set the default geocoder in your environment.rb file.
|
54
|
-
|
55
|
-
Geocode.geocoder = Graticule.service(:yahoo).new 'your_api_key'
|
56
|
-
|
57
|
-
Then, in each model you want to make geocodable, add acts_as_geocodable.
|
58
|
-
|
59
|
-
class Event < ActiveRecord::Base
|
60
|
-
acts_as_geocodable
|
61
|
-
end
|
62
|
-
|
63
|
-
The only requirement is that your model must have address fields. By default, acts_as_geocodable looks for attributes called +street+, +locality+, +region+, +postal_code+, and +country+. To change these, you can provide a mapping in the <tt>:address</tt> option:
|
64
|
-
|
65
|
-
class Event < ActiveRecord::Base
|
66
|
-
acts_as_geocodable :address => {:street => :address1, :locality => :city, :region => :state, :postal_code => :zip}
|
67
|
-
end
|
68
|
-
|
69
|
-
If that doesn't meet your needs, simply override the default +to_location+ method in your model, and return a Graticule::Location with those attributes set.
|
70
|
-
|
71
|
-
acts_as_geocodable can also update your address fields with the data returned from the geocoding service:
|
72
|
-
|
73
|
-
class Event < ActiveRecord::Base
|
74
|
-
acts_as_geocodable :normalize_address => true
|
75
|
-
end
|
76
|
-
|
77
|
-
== IP-based Geocoding
|
78
|
-
|
79
|
-
acts_as_geocodable adds a remote_location method in your controllers that uses http://hostip.info to guess remote users location based on their IP address.
|
80
|
-
|
81
|
-
def index
|
82
|
-
@nearest = Store.origin(remote_location).nearest if remote_location
|
83
|
-
@stores = Store.all
|
84
|
-
end
|
85
|
-
|
86
|
-
Keep in mind that IP-based geocoding is not always accurate, and often will not return any results.
|
87
|
-
|
88
|
-
== Development
|
89
|
-
|
90
|
-
The source code is available at:
|
91
|
-
http://github.com/collectiveidea/acts_as_geocodable
|
92
|
-
git://github.com/collectiveidea/acts_as_geocodable.git
|
93
|
-
|
94
|
-
Patches and suggestions are welcome!
|
95
|
-
|
96
|
-
== To Do
|
97
|
-
|
98
|
-
* configurable formulas
|