geokit 1.6.5 → 1.6.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +15 -0
  2. data/.gitignore +9 -0
  3. data/.travis.yml +13 -0
  4. data/CHANGELOG.md +92 -0
  5. data/Gemfile +4 -0
  6. data/LICENSE +25 -0
  7. data/Manifest.txt +21 -0
  8. data/README.markdown +179 -176
  9. data/Rakefile +8 -1
  10. data/ext/mkrf_conf.rb +15 -0
  11. data/geokit.gemspec +33 -0
  12. data/lib/geokit/geocoders.rb +7 -774
  13. data/lib/geokit/inflectors.rb +38 -0
  14. data/lib/geokit/mappable.rb +61 -3
  15. data/lib/geokit/multi_geocoder.rb +61 -0
  16. data/lib/geokit/services/ca_geocoder.rb +55 -0
  17. data/lib/geokit/services/fcc.rb +57 -0
  18. data/lib/geokit/services/geo_plugin.rb +31 -0
  19. data/lib/geokit/services/geonames.rb +53 -0
  20. data/lib/geokit/services/google.rb +158 -0
  21. data/lib/geokit/services/google3.rb +202 -0
  22. data/lib/geokit/services/ip.rb +103 -0
  23. data/lib/geokit/services/openstreetmap.rb +119 -0
  24. data/lib/geokit/services/us_geocoder.rb +50 -0
  25. data/lib/geokit/services/yahoo.rb +75 -0
  26. data/lib/geokit/version.rb +3 -0
  27. data/test/helper.rb +92 -0
  28. data/test/test_base_geocoder.rb +1 -15
  29. data/test/test_bounds.rb +1 -2
  30. data/test/test_ca_geocoder.rb +1 -1
  31. data/test/test_geoloc.rb +35 -5
  32. data/test/test_geoplugin_geocoder.rb +1 -2
  33. data/test/test_google_geocoder.rb +39 -2
  34. data/test/test_google_geocoder3.rb +55 -3
  35. data/test/test_google_reverse_geocoder.rb +1 -1
  36. data/test/test_inflector.rb +5 -3
  37. data/test/test_ipgeocoder.rb +25 -1
  38. data/test/test_latlng.rb +1 -3
  39. data/test/test_multi_geocoder.rb +1 -1
  40. data/test/test_multi_ip_geocoder.rb +1 -1
  41. data/test/test_openstreetmap_geocoder.rb +161 -0
  42. data/test/test_polygon_contains.rb +101 -0
  43. data/test/test_us_geocoder.rb +1 -1
  44. data/test/test_yahoo_geocoder.rb +18 -1
  45. metadata +164 -83
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ MTI2MTllNDZmNTc3NTBkMzk3MWI1ZWU5MDQ1OWFiMTY3MWFiZjMzMw==
5
+ data.tar.gz: !binary |-
6
+ M2YxZGI0Njc5YjM4Yjg4MGY3NGFhNzdlNWM2MTQxYjQxODk2ZmU3MQ==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ MGQxNjkxNjVmNjk5MDE5ODI1MDdmZDc4OGQ4NzZmOGRjYTdiZmVhNDc4Mjkx
10
+ OTk3NTAxMzRlMmU3OGRmMjc0MjE3MTAzZGMxNGMwYjNiOTU1NGE2NzRlZWU2
11
+ Zjc1ZmFjM2M2Y2NmOGE2MmRhODkzZmUxMzVlZWJiNmRlYWM3NjM=
12
+ data.tar.gz: !binary |-
13
+ NjFhOWQzMmUyNGE5N2Q0YzAyZDcyOGZhNDJhYjY5OTQ1ZDViOGVmZDViNzNi
14
+ OWJjZTk1NTA3NGEzNjY5NjcwMzg4YjI2ODA4Nzk3N2NkNjNlMTcwYzBiZGQx
15
+ NDJjMjFlODE5YjQ2MzRhMmEwYjk5Yzg5NzMxNTcxMmVlYWIyOTE=
@@ -0,0 +1,9 @@
1
+ .loadpath
2
+ .project
3
+ pkg
4
+ .idea
5
+ nbproject
6
+ *.swp
7
+ Gemfile.lock
8
+ *.idea
9
+ coverage
@@ -0,0 +1,13 @@
1
+ language: ruby
2
+ rvm:
3
+ - ree
4
+ - 1.8.7
5
+ - 1.9.2
6
+ - 1.9.3
7
+ - 2.0.0
8
+ script: "bundle exec rake coverage"
9
+ before_install:
10
+ - gem install bundler
11
+ notifications:
12
+ email:
13
+ - michael+geokit@noack.com.au
@@ -0,0 +1,92 @@
1
+ === 1.6.5 / 2012-01-23
2
+
3
+ * first release by @imajes, thanks @andre for all the hard work!
4
+ * normalized whitespace
5
+ * added support for subpremise on google3 encoder
6
+ * fixed yahoo's support by switching to placefinder
7
+ * switched to multi json for agnostic json support
8
+ * removed hoe and replaced with bundler's gem harness
9
+
10
+ === 1.6.0 / 2011-05-27
11
+
12
+ * added Google geocoder3 support (thanks @projectdx)
13
+ * added FCC encoder support (thanks @paulschreiber)
14
+ * various minor fixes.
15
+
16
+ === 1.5.0 / 2009-09-21
17
+ * fixed jruby compatibility (thanks manalang)
18
+ * added country name to Google reverse geocoder (thanks joahking)
19
+ * added DependentLocalityName as district, and SubAdministrativeAreaName as province (google geocoder only)
20
+ * Google geocoder throws an error if you exceed geocoding rates (thanks drogus)
21
+
22
+ === 1.4.1 / 2009-06-15
23
+ * Fixed Ruby 1.9.1 compat and load order (thanks Niels Ganser)
24
+
25
+ === 1.4.0 / 2009-05-27
26
+ * Added country code/viewport biasing to GoogleGeocoder. Added Bounds#to_span method
27
+ * Added suggested_bounds (Geokit::Bounds) property to GeoLoc. (Google geocoder only)
28
+ * Added LatLng#reverse_geocode convenience method (thanks Tisho Georgiev for all three)
29
+
30
+ === 1.3.2 / 2009-05-27
31
+ * Fixed blank address geocoding bug
32
+
33
+ === 1.3.1 / 2009-05-21
34
+ * Support for External geocoders file (thanks dreamcat4)
35
+ * Support multiple ip geocoders, including new setting for ip_provider_order (thanks dreamcat4)
36
+
37
+ === 1.3.0 / 2009-04-11
38
+ * Added capability to define multiple API keys for different domains that may be pointing to the same application (thanks Glenn Powell)
39
+ * Added numeric accuracy accessor for Yahoo and Google geocoders (thanks Andrew Fecheyr Lippens)
40
+ * Implement #hash and #eql? on LatLng to allow for using it as a hash key (thanks Luke Melia and Ross Kaffenberger)
41
+ *
42
+
43
+ === 1.2.6 / 2009-03-19
44
+ * misc minor fixes
45
+
46
+ === 1.2.5 / 2009-02-25
47
+
48
+ * fixed GeoLoc.to_yaml
49
+ * fixed minor google geocoding bug
50
+ * now periodically publishing the Geokit gem to Rubyforge. Still maintaining development and managing contributions at Github
51
+
52
+ === 1.2.4 / 2009-02-25
53
+
54
+ * Improved Google geocoder in the Gem: Support for multiple geocoding results from the Google geocoder. (thanks github/pic)
55
+
56
+ === 1.2.3 / 2009-02-01
57
+
58
+ * Adding GeoPluginGeocoder for IP geocoding (thanks github/xjunior)
59
+ * Ruby 1.9.1 compatibility and Unicode fixes (thanks github/Nielsomat)
60
+ * various bug fixes
61
+
62
+ === 1.2.1 / 2009-01-05
63
+
64
+ * minor bug fixes
65
+ * reverse geocoding added (Google only): res=Geokit::Geocoders::GoogleGeocoder.reverse_geocode "37.791821,-122.394679"
66
+ * nautical miles added (in addition to miles and KM)
67
+
68
+ === 1.2.0 / 2008-12-01
69
+
70
+ * Improved Geocoder.us support -- respects authentication, and can geocode city names or zipcodes alone
71
+ * cross-meridian finds work correctly with bounds conditions
72
+ * fixed a problem with columns with "distance" in their name
73
+ * added Geonames geocoder
74
+ * the gem and plugin are now hosted at Github.
75
+
76
+ === 1.1.1 / 2008-01-20
77
+ * fixes for distance calculation (in-memory and database) when distances are either very small or 0.
78
+ * NOTE: older versions of MySQL/Postgres may not work. See readme for more info.
79
+
80
+ === 1.1.0 / 2007-12-07
81
+ * Geokit is now Rails 2.0 / Edge friendly.
82
+
83
+ === 1.0.0 / 2007-07-22
84
+ * see http://earthcode.com/blog/2007/07/new_geokit_release.html
85
+ * auto geocoding: an option to automatically geocode a model's address field on create
86
+ * in-memory sort-by-distance for arrays of location objects
87
+ * bounding box queries: `Location.find :all, :bounds=>[sw,ne]`
88
+ * improved performance by automatically adding a bounding box condition to radial queries
89
+ * new Bounds class for in-memory bounds-related operations
90
+ * ability to calculate heading and midpoint between two points
91
+ * ability to calculate endpoint given a point, heading, and distance
92
+
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in geokit.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,25 @@
1
+ ## LICENSE
2
+
3
+ (The MIT License)
4
+
5
+ Copyright (c) 2012+ James Cox
6
+ Copyright (c) 2007-2011 Andre Lewis and Bill Eisenhauer
7
+
8
+ Permission is hereby granted, free of charge, to any person obtaining
9
+ a copy of this software and associated documentation files (the
10
+ 'Software'), to deal in the Software without restriction, including
11
+ without limitation the rights to use, copy, modify, merge, publish,
12
+ distribute, sublicense, and/or sell copies of the Software, and to
13
+ permit persons to whom the Software is furnished to do so, subject to
14
+ the following conditions:
15
+
16
+ The above copyright notice and this permission notice shall be
17
+ included in all copies or substantial portions of the Software.
18
+
19
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
20
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
22
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
23
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,21 @@
1
+ History.txt
2
+ Manifest.txt
3
+ README.markdown
4
+ Rakefile
5
+ geokit.gemspec
6
+ lib/geokit.rb
7
+ lib/geokit/geocoders.rb
8
+ lib/geokit/mappable.rb
9
+ test/test_base_geocoder.rb
10
+ test/test_bounds.rb
11
+ test/test_ca_geocoder.rb
12
+ test/test_geoloc.rb
13
+ test/test_geoplugin_geocoder.rb
14
+ test/test_google_geocoder.rb
15
+ test/test_google_reverse_geocoder.rb
16
+ test/test_inflector.rb
17
+ test/test_ipgeocoder.rb
18
+ test/test_latlng.rb
19
+ test/test_multi_geocoder.rb
20
+ test/test_us_geocoder.rb
21
+ test/test_yahoo_geocoder.rb
@@ -1,43 +1,54 @@
1
- ## GEOKIT GEM DESCRIPTION
1
+ Geokit
2
+ ======
3
+
4
+ [![Gem Version](https://badge.fury.io/rb/geokit.png)](http://badge.fury.io/rb/geokit)
5
+ [![Build Status](https://travis-ci.org/geokit/geokit.png?branch=master)](https://travis-ci.org/geokit/geokit)
6
+ [![Coverage Status](https://coveralls.io/repos/geokit/geokit-rails3/badge.png)](https://coveralls.io/r/geokit/geokit)
7
+ [![Dependency Status](https://gemnasium.com/geokit/geokit.png)](https://gemnasium.com/geokit/geokit)
8
+ [![Code Climate](https://codeclimate.com/github/geokit/geokit.png)](https://codeclimate.com/github/geokit/geokit)
9
+
10
+ ## DESCRIPTION
2
11
 
3
12
  The Geokit gem provides:
4
13
 
5
14
  * Distance calculations between two points on the earth. Calculate the distance in miles, kilometers, or nautical miles, with all the trigonometry abstracted away by GeoKit.
6
- * Geocoding from multiple providers. It supports Google, Yahoo, Geocoder.us, and Geocoder.ca geocoders, and others. It provides a uniform response structure from all of them.
15
+ * Geocoding from multiple providers. It supports Google, Yahoo, Geocoder.us, and Geocoder.ca geocoders, and others. It provides a uniform response structure from all of them.
7
16
  It also provides a fail-over mechanism, in case your input fails to geocode in one service.
8
17
  * Rectangular bounds calculations: is a point within a given rectangular bounds?
9
18
  * Heading and midpoint calculations
10
19
 
11
- Combine this gem with the [geokit-rails plugin](http://github.com/andre/geokit-rails/tree/master) to get location-based finders for your Rails app.
20
+ Combine this gem with the [geokit-rails plugin](http://github.com/geokit/geokit-rails) to get location-based finders for your Rails app.
12
21
 
13
- * Geokit Documentation at Rubyforge [http://geokit.rubyforge.org](http://geokit.rubyforge.org).
14
- * Repository at Github: [http://github.com/andre/geokit-gem/tree/master](http://github.com/andre/geokit-gem/tree/master).
15
- * Follow the Google Group for updates and discussion on Geokit: [http://groups.google.com/group/geokit](http://groups.google.com/group/geokit)
22
+ * Repository at Github: [http://github.com/geokit/geokit](http://github.com/geokit/geokit).
23
+ * RDoc pages: [http://rdoc.info/github/geokit/geokit/master/frames](http://rdoc.info/github/geokit/geokit/master/frames)
24
+ * Follow the Google Group for updates and discussion on Geokit: [http://groups.google.com/group/geokit](http://groups.google.com/group/geokit)
16
25
 
17
26
  ## INSTALL
18
27
 
19
- sudo gem install geokit
28
+ gem install geokit
20
29
 
21
30
  ## QUICK START
22
31
 
23
- irb> require 'rubygems'
24
- irb> require 'geokit'
25
- irb> a=Geokit::Geocoders::YahooGeocoder.geocode '140 Market St, San Francisco, CA'
26
- irb> a.ll
27
- => 37.79363,-122.396116
28
- irb> b=Geokit::Geocoders::YahooGeocoder.geocode '789 Geary St, San Francisco, CA'
29
- irb> b.ll
30
- => 37.786217,-122.41619
31
- irb> a.distance_to(b)
32
- => 1.21120007413626
33
- irb> a.heading_to(b)
34
- => 244.959832435678
35
- irb(main):006:0> c=a.midpoint_to(b) # what's halfway from a to b?
36
- irb> c.ll
37
- => "37.7899239257175,-122.406153503469"
38
- irb(main):008:0> d=c.endpoint(90,10) # what's 10 miles to the east of c?
39
- irb> d.ll
40
- => "37.7897825005142,-122.223214776155"
32
+ ```ruby
33
+ irb> require 'rubygems'
34
+ irb> require 'geokit'
35
+ irb> a=Geokit::Geocoders::YahooGeocoder.geocode '140 Market St, San Francisco, CA'
36
+ irb> a.ll
37
+ => 37.79363,-122.396116
38
+ irb> b=Geokit::Geocoders::YahooGeocoder.geocode '789 Geary St, San Francisco, CA'
39
+ irb> b.ll
40
+ => 37.786217,-122.41619
41
+ irb> a.distance_to(b)
42
+ => 1.21120007413626
43
+ irb> a.heading_to(b)
44
+ => 244.959832435678
45
+ irb(main):006:0> c=a.midpoint_to(b) # what's halfway from a to b?
46
+ irb> c.ll
47
+ => "37.7899239257175,-122.406153503469"
48
+ irb(main):008:0> d=c.endpoint(90,10) # what's 10 miles to the east of c?
49
+ irb> d.ll
50
+ => "37.7897825005142,-122.223214776155"
51
+ ```
41
52
 
42
53
  FYI, that `.ll` method means "latitude longitude".
43
54
 
@@ -47,86 +58,88 @@ See the RDOC more more ... there are also operations on rectangular bounds (e.g.
47
58
 
48
59
  If you're using this gem by itself, here are the configuration options:
49
60
 
50
- # These defaults are used in Geokit::Mappable.distance_to and in acts_as_mappable
51
- Geokit::default_units = :miles
52
- Geokit::default_formula = :sphere
53
-
54
- # This is the timeout value in seconds to be used for calls to the geocoder web
55
- # services. For no timeout at all, comment out the setting. The timeout unit
56
- # is in seconds.
57
- Geokit::Geocoders::request_timeout = 3
58
-
59
- # These settings are used if web service calls must be routed through a proxy.
60
- # These setting can be nil if not needed, otherwise, addr and port must be
61
- # filled in at a minimum. If the proxy requires authentication, the username
62
- # and password can be provided as well.
63
- Geokit::Geocoders::proxy_addr = nil
64
- Geokit::Geocoders::proxy_port = nil
65
- Geokit::Geocoders::proxy_user = nil
66
- Geokit::Geocoders::proxy_pass = nil
67
-
68
- # This is your yahoo application key for the Yahoo Geocoder.
69
- # See http://developer.yahoo.com/faq/index.html#appid
70
- # and http://developer.yahoo.com/maps/rest/V1/geocode.html
71
- Geokit::Geocoders::yahoo = 'REPLACE_WITH_YOUR_YAHOO_KEY'
72
-
73
- # This is your Google Maps geocoder key.
74
- # See http://www.google.com/apis/maps/signup.html
75
- # and http://www.google.com/apis/maps/documentation/#Geocoding_Examples
76
- Geokit::Geocoders::google = 'REPLACE_WITH_YOUR_GOOGLE_KEY'
77
-
78
- # You can also set multiple API KEYS for different domains that may be directed to this same application.
79
- # The domain from which the current user is being directed will automatically be updated for Geokit via
80
- # the GeocoderControl class, which gets it's begin filter mixed into the ActionController.
81
- # You define these keys with a Hash as follows:
82
- #Geokit::Geocoders::google = { 'rubyonrails.org' => 'RUBY_ON_RAILS_API_KEY', 'ruby-docs.org' => 'RUBY_DOCS_API_KEY' }
83
-
84
- # This is your username and password for geocoder.us.
85
- # To use the free service, the value can be set to nil or false. For
86
- # usage tied to an account, the value should be set to username:password.
87
- # See http://geocoder.us
88
- # and http://geocoder.us/user/signup
89
- Geokit::Geocoders::geocoder_us = false
90
-
91
- # This is your authorization key for geocoder.ca.
92
- # To use the free service, the value can be set to nil or false. For
93
- # usage tied to an account, set the value to the key obtained from
94
- # Geocoder.ca.
95
- # See http://geocoder.ca
96
- # and http://geocoder.ca/?register=1
97
- Geokit::Geocoders::geocoder_ca = false
98
-
99
- # require "external_geocoder.rb"
100
- # Please see the section "writing your own geocoders" for more information.
101
- # Geokit::Geocoders::external_key = 'REPLACE_WITH_YOUR_API_KEY'
102
-
103
- # This is the order in which the geocoders are called in a failover scenario
104
- # If you only want to use a single geocoder, put a single symbol in the array.
105
- # Valid symbols are :google, :yahoo, :us, and :ca.
106
- # Be aware that there are Terms of Use restrictions on how you can use the
107
- # various geocoders. Make sure you read up on relevant Terms of Use for each
108
- # geocoder you are going to use.
109
- Geokit::Geocoders::provider_order = [:google,:us]
110
-
111
- # The IP provider order. Valid symbols are :ip,:geo_plugin.
112
- # As before, make sure you read up on relevant Terms of Use for each.
113
- # Geokit::Geocoders::ip_provider_order = [:external,:geo_plugin,:ip]
114
-
115
- If you're using this gem with the [geokit-rails plugin](http://github.com/andre/geokit-rails/tree/master), the plugin
61
+ ```ruby
62
+ # These defaults are used in Geokit::Mappable.distance_to and in acts_as_mappable
63
+ Geokit::default_units = :miles
64
+ Geokit::default_formula = :sphere
65
+
66
+ # This is the timeout value in seconds to be used for calls to the geocoder web
67
+ # services. For no timeout at all, comment out the setting. The timeout unit
68
+ # is in seconds.
69
+ Geokit::Geocoders::request_timeout = 3
70
+
71
+ # These settings are used if web service calls must be routed through a proxy.
72
+ # These setting can be nil if not needed, otherwise, addr and port must be
73
+ # filled in at a minimum. If the proxy requires authentication, the username
74
+ # and password can be provided as well.
75
+ Geokit::Geocoders::proxy_addr = nil
76
+ Geokit::Geocoders::proxy_port = nil
77
+ Geokit::Geocoders::proxy_user = nil
78
+ Geokit::Geocoders::proxy_pass = nil
79
+
80
+ # This is your yahoo application key for the Yahoo Geocoder.
81
+ # See http://developer.yahoo.com/faq/index.html#appid
82
+ # and http://developer.yahoo.com/maps/rest/V1/geocode.html
83
+ Geokit::Geocoders::yahoo = 'REPLACE_WITH_YOUR_YAHOO_KEY'
84
+
85
+ # This is your Google Maps geocoder key.
86
+ # See http://www.google.com/apis/maps/signup.html
87
+ # and http://www.google.com/apis/maps/documentation/#Geocoding_Examples
88
+ Geokit::Geocoders::google = 'REPLACE_WITH_YOUR_GOOGLE_KEY'
89
+
90
+ # You can also set multiple API KEYS for different domains that may be directed to this same application.
91
+ # The domain from which the current user is being directed will automatically be updated for Geokit via
92
+ # the GeocoderControl class, which gets it's begin filter mixed into the ActionController.
93
+ # You define these keys with a Hash as follows:
94
+ #Geokit::Geocoders::google = { 'rubyonrails.org' => 'RUBY_ON_RAILS_API_KEY', 'ruby-docs.org' => 'RUBY_DOCS_API_KEY' }
95
+
96
+ # This is your username and password for geocoder.us.
97
+ # To use the free service, the value can be set to nil or false. For
98
+ # usage tied to an account, the value should be set to username:password.
99
+ # See http://geocoder.us
100
+ # and http://geocoder.us/user/signup
101
+ Geokit::Geocoders::geocoder_us = false
102
+
103
+ # This is your authorization key for geocoder.ca.
104
+ # To use the free service, the value can be set to nil or false. For
105
+ # usage tied to an account, set the value to the key obtained from
106
+ # Geocoder.ca.
107
+ # See http://geocoder.ca
108
+ # and http://geocoder.ca/?register=1
109
+ Geokit::Geocoders::geocoder_ca = false
110
+
111
+ # require "external_geocoder.rb"
112
+ # Please see the section "writing your own geocoders" for more information.
113
+ # Geokit::Geocoders::external_key = 'REPLACE_WITH_YOUR_API_KEY'
114
+
115
+ # This is the order in which the geocoders are called in a failover scenario
116
+ # If you only want to use a single geocoder, put a single symbol in the array.
117
+ # Valid symbols are :google, :yahoo, :us, and :ca.
118
+ # Be aware that there are Terms of Use restrictions on how you can use the
119
+ # various geocoders. Make sure you read up on relevant Terms of Use for each
120
+ # geocoder you are going to use.
121
+ Geokit::Geocoders::provider_order = [:google,:us]
122
+
123
+ # The IP provider order. Valid symbols are :ip,:geo_plugin.
124
+ # As before, make sure you read up on relevant Terms of Use for each.
125
+ # Geokit::Geocoders::ip_provider_order = [:external,:geo_plugin,:ip]
126
+ ```
127
+
128
+ If you're using this gem with the [geokit-rails plugin](http://github.com/geokit/geokit-rails), the plugin
116
129
  creates a template with these settings and places it in `config/initializers/geokit_config.rb`.
117
130
 
118
131
  ## SUPPORTED GEOCODERS
119
132
 
120
- ### "regular" address geocoders
133
+ ### "regular" address geocoders
121
134
  * Yahoo Geocoder - requires an API key.
122
135
  * Geocoder.us - may require authentication if performing more than the free request limit.
123
136
  * Geocoder.ca - for Canada; may require authentication as well.
124
137
  * Geonames - a free geocoder
125
138
 
126
- ### address geocoders that also provide reverse geocoding
139
+ ### address geocoders that also provide reverse geocoding
127
140
  * Google Geocoder - requires an API key. Also supports multiple results and bounding box/country code biasing.
128
141
 
129
- ### IP address geocoders
142
+ ### IP address geocoders
130
143
  * IP Geocoder - geocodes an IP address using hostip.info's web service.
131
144
  * Geoplugin.net -- another IP address geocoder
132
145
 
@@ -134,61 +147,73 @@ creates a template with these settings and places it in `config/initializers/geo
134
147
 
135
148
  The Google Geocoder sports a number of useful tricks that elevate it a little bit above the rest of the currently supported geocoders. For starters, it returns a `suggested_bounds` property for all your geocoded results, so you can more easily decide where and how to center a map on the places you geocode. Here's a quick example:
136
149
 
150
+ ```ruby
137
151
  irb> res = Geokit::Geocoders::GoogleGeocoder.geocode('140 Market St, San Francisco, CA')
138
- irb> pp res.suggested_bounds
139
- #<Geokit::Bounds:0x53b36c
140
- @ne=#<Geokit::LatLng:0x53b204 @lat=37.7968528, @lng=-122.3926933>,
141
- @sw=#<Geokit::LatLng:0x53b2b8 @lat=37.7905576, @lng=-122.3989885>>
152
+ irb> pp res.suggested_bounds
153
+ #<Geokit::Bounds:0x53b36c
154
+ @ne=#<Geokit::LatLng:0x53b204 @lat=37.7968528, @lng=-122.3926933>,
155
+ @sw=#<Geokit::LatLng:0x53b2b8 @lat=37.7905576, @lng=-122.3989885>>
142
156
 
143
157
  In addition, you can use viewport or country code biasing to make sure the geocoders prefers results within a specific area. Say we wanted to geocode the city of Syracuse in Italy. A normal geocoding query would look like this:
144
158
 
145
- irb> res = Geokit::Geocoders::GoogleGeocoder.geocode('Syracuse')
146
- irb> res.full_address
147
- => "Syracuse, NY, USA"
148
-
159
+ irb> res = Geokit::Geocoders::GoogleGeocoder.geocode('Syracuse')
160
+ irb> res.full_address
161
+ => "Syracuse, NY, USA"
162
+ ```
163
+
149
164
  Not exactly what we were looking for. We know that Syracuse is in Italy, so we can tell the Google Geocoder to prefer results from Italy first, and then wander the Syracuses of the world. To do that, we have to pass Italy's ccTLD (country code top-level domain) to the `:bias` option of the `geocode` method. You can find a comprehensive list of all ccTLDs here: http://en.wikipedia.org/wiki/CcTLD.
150
165
 
151
- irb> res = Geokit::Geocoders::GoogleGeocoder.geocode('Syracuse', :bias => 'it')
152
- irb> res.full_address
153
- => "Syracuse, Italy"
166
+ ```ruby
167
+ irb> res = Geokit::Geocoders::GoogleGeocoder.geocode('Syracuse', :bias => 'it')
168
+ irb> res.full_address
169
+ => "Syracuse, Italy"
170
+ ```
154
171
 
155
172
  Alternatively, we can speficy the geocoding bias as a bounding box object. Say we wanted to geocode the Winnetka district in Los Angeles.
156
173
 
157
- irb> res = Geokit::Geocoders::GoogleGeocoder.geocode('Winnetka')
158
- irb> res.full_address
159
- => "Winnetka, IL, USA"
160
-
174
+ ```ruby
175
+ irb> res = Geokit::Geocoders::GoogleGeocoder.geocode('Winnetka')
176
+ irb> res.full_address
177
+ => "Winnetka, IL, USA"
178
+ ```
179
+
161
180
  Not it. What we can do is tell the geocoder to return results only from in and around LA.
162
181
 
163
- irb> la_bounds = Geokit::Geocoders::GoogleGeocoder.geocode('Los Angeles').suggested_bounds
164
- irb> res = Geokit::Geocoders::GoogleGeocoder.geocode('Winnetka', :bias => la_bounds)
165
- irb> res.full_address
166
- => "Winnetka, California, USA"
182
+ ```ruby
183
+ irb> la_bounds = Geokit::Geocoders::GoogleGeocoder.geocode('Los Angeles').suggested_bounds
184
+ irb> res = Geokit::Geocoders::GoogleGeocoder.geocode('Winnetka', :bias => la_bounds)
185
+ irb> res.full_address
186
+ => "Winnetka, California, USA"
187
+ ```
167
188
 
168
189
 
169
190
  ### The Multigeocoder
170
191
  Multi Geocoder - provides failover for the physical location geocoders, and also IP address geocoders. Its configured by setting Geokit::Geocoders::provider_order, and Geokit::Geocoders::ip_provider_order. You should call the Multi-Geocoder with its :geocode method, supplying one address parameter which is either a real street address, or an ip address. For example:
171
192
 
172
- Geokit::Geocoders::MultiGeocoder.geocode("900 Sycamore Drive")
193
+ ```ruby
194
+ Geokit::Geocoders::MultiGeocoder.geocode("900 Sycamore Drive")
173
195
 
174
- Geokit::Geocoders::MultiGeocoder.geocode("12.12.12.12")
196
+ Geokit::Geocoders::MultiGeocoder.geocode("12.12.12.12")
197
+ ```
175
198
 
176
199
  ## MULTIPLE RESULTS
177
- Some geocoding services will return multple results if the there isn't one clear result.
178
- Geoloc can capture multiple results through its "all" method. Currently only the Google geocoder
200
+ Some geocoding services will return multple results if the there isn't one clear result.
201
+ Geoloc can capture multiple results through its "all" method. Currently only the Google geocoder
179
202
  supports multiple results:
180
203
 
181
- irb> geo=Geokit::Geocoders::GoogleGeocoder.geocode("900 Sycamore Drive")
182
- irb> geo.full_address
183
- => "900 Sycamore Dr, Arkadelphia, AR 71923, USA"
184
- irb> geo.all.size
185
- irb> geo.all.each { |e| puts e.full_address }
186
- 900 Sycamore Dr, Arkadelphia, AR 71923, USA
187
- 900 Sycamore Dr, Burkburnett, TX 76354, USA
188
- 900 Sycamore Dr, TN 38361, USA
189
- ....
190
-
191
- geo.all is just an array of additional Geolocs, so do what you want with it. If you call .all on a
204
+ ```ruby
205
+ irb> geo=Geokit::Geocoders::GoogleGeocoder.geocode("900 Sycamore Drive")
206
+ irb> geo.full_address
207
+ => "900 Sycamore Dr, Arkadelphia, AR 71923, USA"
208
+ irb> geo.all.size
209
+ irb> geo.all.each { |e| puts e.full_address }
210
+ 900 Sycamore Dr, Arkadelphia, AR 71923, USA
211
+ 900 Sycamore Dr, Burkburnett, TX 76354, USA
212
+ 900 Sycamore Dr, TN 38361, USA
213
+ ....
214
+ ```
215
+
216
+ geo.all is just an array of additional Geolocs, so do what you want with it. If you call .all on a
192
217
  geoloc that doesn't have any additional results, you will get an array of one.
193
218
 
194
219
 
@@ -196,10 +221,10 @@ geoloc that doesn't have any additional results, you will get an array of one.
196
221
 
197
222
  mappable.rb contains the Mappable module, which provides basic
198
223
  distance calculation methods, i.e., calculating the distance
199
- between two points.
224
+ between two points.
200
225
 
201
226
  mappable.rb also contains LatLng, GeoLoc, and Bounds.
202
- LatLng is a simple container for latitude and longitude, but
227
+ LatLng is a simple container for latitude and longitude, but
203
228
  it's made more powerful by mixing in the above-mentioned Mappable
204
229
  module -- therefore, you can calculate easily the distance between two
205
230
  LatLng ojbects with `distance = first.distance_to(other)`
@@ -209,7 +234,7 @@ has been geocoded. You can get the city, zipcode, street address, etc.
209
234
  from a GeoLoc object. GeoLoc extends LatLng, so you also get lat/lng
210
235
  AND the Mappable modeule goodness for free.
211
236
 
212
- geocoders.rb contains all the geocoder implemenations. All the gercoders
237
+ geocoders.rb contains all the geocoder implemenations. All the gercoders
213
238
  inherit from a common base (class Geocoder) and implement the private method
214
239
  do_geocode.
215
240
 
@@ -218,56 +243,34 @@ do_geocode.
218
243
  If you would like to write your own geocoders, you can do so by requiring 'geokit' or 'geokit/geocoders.rb' in a new file and subclassing the base class (which is class "Geocoder").
219
244
  You must then also require such extenal file back in your main geokit configuration.
220
245
 
221
- require "geokit"
222
-
223
- module Geokit
224
- module Geocoders
225
-
226
- # Should be overriden as Geokit::Geocoders::external_key in your configuration file
227
- @@external_key = 'REPLACE_WITH_YOUR_API_KEY'
228
- __define_accessors
229
-
230
- # Replace name 'External' (below) with the name of your custom geocoder class
231
- # and use :external to specify this geocoder in your list of geocoders.
232
- class ExternalGeocoder < Geocoder
233
- private
234
- def self.do_geocode(address, options = {})
235
- # Main geocoding method
236
- end
237
-
238
- def self.parse_http_resp(body) # :nodoc:
239
- # Helper method to parse http response. See geokit/geocoders.rb.
240
- end
241
- end
242
-
243
- end
244
- end
246
+ ```ruby
247
+ require "geokit"
245
248
 
246
- ## GOOGLE GROUP
249
+ module Geokit
250
+ module Geocoders
247
251
 
248
- Follow the Google Group for updates and discussion on Geokit: http://groups.google.com/group/geokit
252
+ # Should be overriden as Geokit::Geocoders::external_key in your configuration file
253
+ @@external_key = 'REPLACE_WITH_YOUR_API_KEY'
254
+ __define_accessors
249
255
 
250
- ## LICENSE
256
+ # Replace name 'External' (below) with the name of your custom geocoder class
257
+ # and use :external to specify this geocoder in your list of geocoders.
258
+ class ExternalGeocoder < Geocoder
259
+ private
260
+ def self.do_geocode(address, options = {})
261
+ # Main geocoding method
262
+ end
251
263
 
252
- (The MIT License)
264
+ def self.parse_http_resp(body) # :nodoc:
265
+ # Helper method to parse http response. See geokit/geocoders.rb.
266
+ end
267
+ end
253
268
 
254
- Copyright (c) 2007-2009 Andre Lewis and Bill Eisenhauer
269
+ end
270
+ end
271
+ ```
255
272
 
256
- Permission is hereby granted, free of charge, to any person obtaining
257
- a copy of this software and associated documentation files (the
258
- 'Software'), to deal in the Software without restriction, including
259
- without limitation the rights to use, copy, modify, merge, publish,
260
- distribute, sublicense, and/or sell copies of the Software, and to
261
- permit persons to whom the Software is furnished to do so, subject to
262
- the following conditions:
273
+ ## GOOGLE GROUP
263
274
 
264
- The above copyright notice and this permission notice shall be
265
- included in all copies or substantial portions of the Software.
275
+ Follow the Google Group for updates and discussion on Geokit: http://groups.google.com/group/geokit
266
276
 
267
- THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
268
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
269
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
270
- IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
271
- CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
272
- TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
273
- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.