rails-geocoder 0.9.3 → 0.9.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGELOG.rdoc CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  Per-release changes to Geocoder.
4
4
 
5
+ == 0.9.4 (2010 Aug 2)
6
+
7
+ * Google Maps API key no longer required (uses geocoder v3).
8
+
5
9
  == 0.9.3 (2010 Aug 2)
6
10
 
7
11
  * Fix incompatibility with Rails 3 RC 1.
data/README.rdoc CHANGED
@@ -1,10 +1,8 @@
1
1
  = Geocoder
2
2
 
3
- Geocoder adds object geocoding and database-agnostic distance calculations to Ruby on Rails. It's as simple as calling <tt>fetch_coordinates!</tt> on your objects, and then using a scope like <tt>Venue.near("Billings, MT")</tt>.
3
+ Geocoder adds object geocoding and database-agnostic distance calculations to Ruby on Rails. It's as simple as calling <tt>fetch_coordinates!</tt> on your objects, and then using a scope like <tt>Venue.near("Billings, MT")</tt>. Since it does not rely on proprietary database functions finding geocoded objects in a given area works with out-of-the-box MySQL or even SQLite.
4
4
 
5
- Geocoder does not rely on proprietary database functions so finding geocoded objects in a given area is easily done using out-of-the-box MySQL or even SQLite.
6
-
7
- <b>Geocoder is currently compatible with Rails 2.x and Rails 3.</b>
5
+ <b>Geocoder is currently compatible with Rails 2.x and Rails 3.</b> Also, a Google Maps API key is no longer necessary.
8
6
 
9
7
 
10
8
  == 1. Install
@@ -41,21 +39,16 @@ or as a gem:
41
39
 
42
40
  == 2. Configure
43
41
 
44
- A) Get a Google Maps API key (see http://code.google.com/apis/maps/signup.html) and store it in a constant:
45
-
46
- # eg, in config/initializers/google_maps.rb
47
- GOOGLE_MAPS_API_KEY = "..."
48
-
49
- B) Add +latitude+ and +longitude+ columns to your model:
42
+ A) Add +latitude+ and +longitude+ columns to your model:
50
43
 
51
44
  script/generate migration AddLatitudeAndLongitudeToYourModel latitude:float longitude:float
52
45
  rake db:migrate
53
46
 
54
- C) Tell geocoder where your model stores its address:
47
+ B) Tell geocoder where your model stores its address:
55
48
 
56
49
  geocoded_by :address
57
50
 
58
- D) Optionally, auto-fetch coordinates every time your model is saved:
51
+ C) Optionally, auto-fetch coordinates every time your model is saved:
59
52
 
60
53
  after_validation :fetch_coordinates
61
54
 
@@ -154,9 +147,6 @@ If anyone has a more elegant solution to this problem I am very interested in se
154
147
  * make 'near' scope work with 'select' options
155
148
  * prepend table names to column names in SQL distance expression (required
156
149
  to do joins on another geocoded model)
157
- * prevent NameError when GOOGLE_MAPS_API_KEY is missing: show nice msg
158
- * <tt>install.rb</tt> should do some setup when installed as a plugin
159
- * create initializer with GOOGLE_MAPS_API_KEY?
160
150
 
161
151
 
162
152
  Copyright (c) 2009-10 Alex Reisner, released under the MIT license
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.9.3
1
+ 0.9.4
data/lib/geocoder.rb CHANGED
@@ -181,10 +181,10 @@ module Geocoder
181
181
  if options != {}
182
182
  warn "DEPRECATION WARNING: The 'options' argument to the nearbys " +
183
183
  "method is deprecated and will be removed from rails-geocoder in " +
184
- "version 0.9.4. Nearbys now returns a scope so you should specify " +
185
- "more scopes and/or conditions via chaining. For example: " +
184
+ "a future version. Nearbys now returns a scope so you should " +
185
+ "specify more scopes and/or conditions via chaining. For example: " +
186
186
  "city.nearbys(20).order('name').limit(10). Support for Rails 2.x " +
187
- "will be discontinued after rails-geocoder 0.9.3."
187
+ "will be discontinued soon."
188
188
  end
189
189
  return [] unless geocoded?
190
190
  options.reverse_merge!(:conditions => ["id != ?", id])
@@ -223,15 +223,14 @@ module Geocoder
223
223
  return nil unless doc = self.search(query)
224
224
 
225
225
  # make sure search found a result
226
- e = doc.elements['kml/Response/Status/code']
227
- return nil unless (e and e.text == "200")
228
-
226
+ e = doc.elements['GeocodeResponse/status']
227
+ return nil unless (e and e.text == "OK")
228
+
229
229
  # isolate the relevant part of the result
230
- place = doc.elements['kml/Response/Placemark']
230
+ place = doc.elements['GeocodeResponse/result/geometry/location']
231
231
 
232
- # if there are multiple results, blindly use the first
233
- coords = place.elements['Point/coordinates'].text
234
- coords.split(',')[0...2].reverse.map{ |i| i.to_f }
232
+ # blindly use the first results (assume they are most accurate)
233
+ ['lat', 'lng'].map{ |i| place.elements[i].text.to_f }
235
234
  end
236
235
 
237
236
  ##
@@ -331,13 +330,10 @@ module Geocoder
331
330
  #
332
331
  def self._fetch_xml(query)
333
332
  params = {
334
- :q => query,
335
- :key => GOOGLE_MAPS_API_KEY,
336
- :output => "xml",
337
- :sensor => "false",
338
- :oe => "utf8"
333
+ :address => query,
334
+ :sensor => "false"
339
335
  }
340
- url = "http://maps.google.com/maps/geo?" + params.to_query
336
+ url = "http://maps.google.com/maps/api/geocode/xml?" + params.to_query
341
337
 
342
338
  # Query geocoder and make sure it responds quickly.
343
339
  begin
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{rails-geocoder}
8
- s.version = "0.9.3"
8
+ s.version = "0.9.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Alex Reisner"]
@@ -1,16 +1,69 @@
1
- <?xml version="1.0" encoding="UTF-8" ?>
2
- <kml xmlns="http://earth.google.com/kml/2.0"><Response>
3
- <name>4 Penn Plaza, New York, NY</name>
4
- <Status>
5
- <code>200</code>
6
- <request>geocode</request>
7
- </Status>
8
- <Placemark id="p1">
9
- <address>4 Penn Plaza, New York, NY 10001, USA</address>
10
- <AddressDetails Accuracy="8" xmlns="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"><Country><CountryNameCode>US</CountryNameCode><CountryName>USA</CountryName><AdministrativeArea><AdministrativeAreaName>NY</AdministrativeAreaName><SubAdministrativeArea><SubAdministrativeAreaName>New York</SubAdministrativeAreaName><Locality><LocalityName>New York</LocalityName><Thoroughfare><ThoroughfareName>4 Penn Plaza</ThoroughfareName></Thoroughfare><PostalCode><PostalCodeNumber>10001</PostalCodeNumber></PostalCode></Locality></SubAdministrativeArea></AdministrativeArea></Country></AddressDetails>
11
- <ExtendedData>
12
- <LatLonBox north="40.7527158" south="40.7464206" east="-73.9885076" west="-73.9948028" />
13
- </ExtendedData>
14
- <Point><coordinates>-73.9916733,40.7495760,0</coordinates></Point>
15
- </Placemark>
16
- </Response></kml>
1
+ <GeocodeResponse>
2
+ <status>OK</status>
3
+ <result>
4
+ <type>street_address</type>
5
+ <formatted_address>4 Penn Plaza, New York, NY 10001, USA</formatted_address>
6
+ <address_component>
7
+ <long_name>4</long_name>
8
+ <short_name>4</short_name>
9
+ <type>street_number</type>
10
+ </address_component>
11
+ <address_component>
12
+ <long_name>Penn Plaza</long_name>
13
+ <short_name>Penn Plaza</short_name>
14
+ <type>route</type>
15
+ </address_component>
16
+ <address_component>
17
+ <long_name>Manhattan</long_name>
18
+ <short_name>Manhattan</short_name>
19
+ <type>sublocality</type>
20
+ <type>political</type>
21
+ </address_component>
22
+ <address_component>
23
+ <long_name>New York</long_name>
24
+ <short_name>New York</short_name>
25
+ <type>locality</type>
26
+ <type>political</type>
27
+ </address_component>
28
+ <address_component>
29
+ <long_name>New York</long_name>
30
+ <short_name>New York</short_name>
31
+ <type>administrative_area_level_2</type>
32
+ <type>political</type>
33
+ </address_component>
34
+ <address_component>
35
+ <long_name>New York</long_name>
36
+ <short_name>NY</short_name>
37
+ <type>administrative_area_level_1</type>
38
+ <type>political</type>
39
+ </address_component>
40
+ <address_component>
41
+ <long_name>United States</long_name>
42
+ <short_name>US</short_name>
43
+ <type>country</type>
44
+ <type>political</type>
45
+ </address_component>
46
+ <address_component>
47
+ <long_name>10001</long_name>
48
+ <short_name>10001</short_name>
49
+ <type>postal_code</type>
50
+ </address_component>
51
+ <geometry>
52
+ <location>
53
+ <lat>40.7503540</lat>
54
+ <lng>-73.9933710</lng>
55
+ </location>
56
+ <location_type>ROOFTOP</location_type>
57
+ <viewport>
58
+ <southwest>
59
+ <lat>40.7473324</lat>
60
+ <lng>-73.9965316</lng>
61
+ </southwest>
62
+ <northeast>
63
+ <lat>40.7536276</lat>
64
+ <lng>-73.9902364</lng>
65
+ </northeast>
66
+ </viewport>
67
+ </geometry>
68
+ </result>
69
+ </GeocodeResponse>
@@ -4,8 +4,8 @@ class GeocoderTest < Test::Unit::TestCase
4
4
 
5
5
  def test_fetch_coordinates
6
6
  v = Venue.new(*venue_params(:msg))
7
- assert_equal [40.7495760, -73.9916733], v.fetch_coordinates
8
- assert_equal [40.7495760, -73.9916733], [v.latitude, v.longitude]
7
+ assert_equal [40.750354, -73.993371], v.fetch_coordinates
8
+ assert_equal [40.750354, -73.993371], [v.latitude, v.longitude]
9
9
  end
10
10
 
11
11
  # sanity check
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 9
8
- - 3
9
- version: 0.9.3
8
+ - 4
9
+ version: 0.9.4
10
10
  platform: ruby
11
11
  authors:
12
12
  - Alex Reisner