geo_magic 0.2.2.1 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -77,8 +77,16 @@ h2. Extra features
77
77
 
78
78
  Lots of extra features has been added recently. For now, please check out the specs to get an idea of the features included.
79
79
  Most recently I have added support to filter a list of points for those who are within a radius of another point (see _select_neares_spec.rb_).
80
+
81
+ h3. Geocoder adapters
82
+
80
83
  I have also just created a Geocode adapter for _Geocode_ and _Graticule_ (see: _geocoder_spec.rb_) - This can also easily be configured for Rails.
81
84
 
85
+ I recently discovered that the Geocode adapter didn't work for all addresses, so I made some improvements to make it more "stable".
86
+ I'm sure there are still corner cases it wont handle, so please join in the effort to fix this!
87
+
88
+ Also note that the API has changed a little bit, so that it uses the same GeoMagic namespace as the rest of _geo_magic_.
89
+
82
90
  h3. Create random points in Radius
83
91
 
84
92
  * @create_points_in_square@
@@ -90,17 +98,23 @@ Within distance:
90
98
 
91
99
  <pre>@points.as_map_points.within_distance 4.km, :from => @center_point</pre>
92
100
 
93
- The closest n:
101
+ The closest n points:
94
102
 
95
103
  <pre>@points.as_map_points.the_closest 4, :from => @center_point</pre>
96
104
 
105
+ Or using container objects (objects containing a location):
106
+
107
+ @people.as_map_points.the_closest 4, :from => @house
108
+
109
+ Where @people is an array of Person and @house is an instance of House and where both House and Person has a #location, #to_point or #point method that returns an object
110
+ with latitude and longitude methods that each return a float.
111
+
97
112
  Within bounding rectangle:
98
113
 
99
114
  <pre>rectangle = GeoMagic::Rectangle.new(GeoMagic::Point.new(-115, 50), GeoMagic::Point.new(-100, 20))
100
115
  # or
101
116
  # rect = GeoMagic::Rectangle.create_from_coords lat1, long1, lat2, long2
102
117
  @points.as_map_points.within_rectangle rect, :from => @center_point
103
-
104
118
  </pre>
105
119
 
106
120
  h2. Meta magic
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.2.1
1
+ 0.2.3
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{geo_magic}
8
- s.version = "0.2.2.1"
8
+ s.version = "0.2.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Kristian Mandrup"]
12
- s.date = %q{2011-01-21}
12
+ s.date = %q{2011-01-22}
13
13
  s.description = %q{Get IP and location data using freegeoip.net - can also calculate of distance between map points using haversine supporting multiple distance units}
14
14
  s.email = %q{kmandrup@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -40,7 +40,7 @@ Gem::Specification.new do |s|
40
40
  "lib/geo_magic/remote.rb",
41
41
  "lib/geo_magic/util.rb",
42
42
  "lib/rails/config.rb",
43
- "spec/fixtures/config.yaml",
43
+ "spec/fixtures/map_api_keys.yaml",
44
44
  "spec/geo_magic/calculate_spec.rb",
45
45
  "spec/geo_magic/geocoder_spec.rb",
46
46
  "spec/geo_magic/include_calc_spec.rb",
@@ -1,4 +1,4 @@
1
- module GeoMap
1
+ module GeoMagic
2
2
  module ServiceAdapter
3
3
  attr_reader :geo_coder, :config
4
4
 
@@ -3,7 +3,7 @@ require 'active_support/inflector'
3
3
  require 'geocode'
4
4
  require 'graticule'
5
5
 
6
- module GeoMap
6
+ module GeoMagic
7
7
  class GeoAdapter
8
8
  attr_accessor :service_name, :environment
9
9
 
@@ -53,32 +53,41 @@ module GeoMap
53
53
  geo_coder.geocode(location_str).extend GeocodeAPI
54
54
  end
55
55
 
56
- module GeocodeAPI
57
- def country
58
- country_api["CountryNameCode"]
56
+ module GeocodeAPI
57
+ # Address
58
+
59
+ def street
60
+ thoroughfare["ThoroughfareName"]
59
61
  end
60
62
 
61
- def country_name
62
- country_api["CountryName"]
63
- end
64
-
65
- def state
66
- adm_api["AdministrativeAreaName"]
67
- end
68
-
69
63
  def postal_code
70
- subadm_api["Locality"]["PostalCode"]["PostalCodeNumber"]
64
+ locality["PostalCode"]["PostalCodeNumber"]
71
65
  end
72
66
  alias_method :zip, :postal_code
73
67
 
74
- def street
75
- subadm_api["Thoroughfare"]["ThoroughfareName"]
76
- end
77
-
78
68
  def city
79
69
  subadm_api["SubAdministrativeAreaName"]
80
70
  end
81
71
 
72
+ def state
73
+ adm_api["AdministrativeAreaName"]
74
+ end
75
+
76
+ def country_code
77
+ country_api["CountryNameCode"]
78
+ end
79
+
80
+ def country_name
81
+ country_api["CountryName"].gsub(/Bundesrepublik /, '')
82
+ end
83
+ alias_method :country, :country_name
84
+
85
+ def address_hash
86
+ {:street => street, :postal_code => postal_code, :city => city, :state => state, :country => country, :country_code => country_code}
87
+ end
88
+
89
+ # Location
90
+
82
91
  def latitude
83
92
  coords[1]
84
93
  end
@@ -86,9 +95,31 @@ module GeoMap
86
95
  def longitude
87
96
  coords[0]
88
97
  end
98
+
99
+ def location_hash
100
+ {:longitude => longitude, :latitude => latitude}
101
+ end
89
102
 
90
103
  protected
91
104
 
105
+ def thoroughfare
106
+ @thoroughfare ||= begin
107
+ thorough = [:subadm_api, :locality_api, :dependent_locality_api].select do |api|
108
+ send(api)["Thoroughfare"]
109
+ end
110
+ send(thorough.first)["Thoroughfare"]
111
+ end
112
+ end
113
+
114
+ def locality
115
+ @locality ||= begin
116
+ thorough = [:locality_api, :dependent_locality_api].select do |api|
117
+ send(api)["PostalCode"]
118
+ end
119
+ send(thorough.first)
120
+ end
121
+ end
122
+
92
123
  def api
93
124
  data["Placemark"].first
94
125
  end
@@ -112,6 +143,14 @@ module GeoMap
112
143
  def subadm_api
113
144
  adm_api["SubAdministrativeArea"]
114
145
  end
146
+
147
+ def locality_api
148
+ subadm_api["Locality"]
149
+ end
150
+
151
+ def dependent_locality_api
152
+ locality_api["DependentLocality"]
153
+ end
115
154
  end
116
155
 
117
156
  def reverse_geocode latitude, longitude
@@ -125,7 +164,7 @@ module GeoMap
125
164
  service_name = options[:service_name] || :google
126
165
  type = options[:type] || :geocode
127
166
  env = options[:env]
128
- "GeoMap::#{type.to_s.classify}Adapter".constantize.new service_name, env
167
+ "GeoMagic::#{type.to_s.classify}Adapter".constantize.new service_name, env
129
168
  end
130
169
 
131
170
  def geocode location_str
@@ -1,4 +1,4 @@
1
- module GeoMap
1
+ module GeoMagic
2
2
  module RailsServiceAdapter
3
3
  attr_reader :geo_coder
4
4
 
@@ -17,7 +17,7 @@ module GeoMap
17
17
  end
18
18
 
19
19
  def config
20
- @config ||= ::YAML.load_file("#{::Rails.root}/config/google_map.yml")[env]
20
+ @config ||= ::YAML.load_file("#{::Rails.root}/config/map_api_keys.yml")[env]
21
21
  end
22
22
 
23
23
  def google_key
@@ -1,2 +1,4 @@
1
1
  development:
2
2
  google_key: "ABQIAAAAUzkItq4p7LYo2YIR_gtjpRTJQa0g3IQ9GZqIMmInSLzwtGDKaBSzEc8_FNxIfQLkpKOh9R4JB87Rig"
3
+ test:
4
+ google_key: "ABQIAAAAUzkItq4p7LYo2YIR_gtjpRTJQa0g3IQ9GZqIMmInSLzwtGDKaBSzEc8_FNxIfQLkpKOh9R4JB87Rig"
@@ -3,8 +3,8 @@ require 'geo_magic'
3
3
 
4
4
  describe "GeoMagic Geocoder" do
5
5
  before do
6
- @geocoder = GeoMap.geo_coder
7
- @geocoder.configure File.expand_path('../fixtures/config.yaml', File.dirname(__FILE__)), :development
6
+ @geocoder = GeoMagic.geo_coder
7
+ @geocoder.configure File.expand_path('../fixtures/map_api_keys.yaml', File.dirname(__FILE__)), :development
8
8
  end
9
9
 
10
10
  it "should geocode" do
@@ -18,8 +18,21 @@ describe "GeoMagic Geocoder" do
18
18
  p location.longitude
19
19
  end
20
20
 
21
+ it "should create location and address hashes" do
22
+ location = @geocoder.instance.geocode "Marienplatz 14, munich, Germany"
23
+ p location.location_hash
24
+ p location.address_hash
25
+ end
26
+
27
+ # Geocoder with Rails 3
28
+
29
+ # Expects map api keys (fx for google maps) to be defined in ROOT/config/map_api_keys.yml
30
+ # See spec/fixtures/map_api_keys.yml for example
31
+
32
+ # Use @geocoder.configure(path, env) to customize this
33
+
21
34
  # it "should geocode for rails" do
22
- # @geocoder = GeoMap.geo_coder :env => :rails
35
+ # @geocoder = GeoMap.geo_coder(:env => :rails)
23
36
  # location = @geocoder.instance.geocode "Mullerstrasse 9, Munich"
24
37
  # location.city.should == 'Munich'
25
38
  # end
metadata CHANGED
@@ -5,9 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 2
9
- - 1
10
- version: 0.2.2.1
8
+ - 3
9
+ version: 0.2.3
11
10
  platform: ruby
12
11
  authors:
13
12
  - Kristian Mandrup
@@ -15,7 +14,7 @@ autorequire:
15
14
  bindir: bin
16
15
  cert_chain: []
17
16
 
18
- date: 2011-01-21 00:00:00 +01:00
17
+ date: 2011-01-22 00:00:00 +01:00
19
18
  default_executable:
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
@@ -169,7 +168,7 @@ files:
169
168
  - lib/geo_magic/remote.rb
170
169
  - lib/geo_magic/util.rb
171
170
  - lib/rails/config.rb
172
- - spec/fixtures/config.yaml
171
+ - spec/fixtures/map_api_keys.yaml
173
172
  - spec/geo_magic/calculate_spec.rb
174
173
  - spec/geo_magic/geocoder_spec.rb
175
174
  - spec/geo_magic/include_calc_spec.rb
@@ -193,7 +192,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
193
192
  requirements:
194
193
  - - ">="
195
194
  - !ruby/object:Gem::Version
196
- hash: -191356599515187652
195
+ hash: -701075083202968492
197
196
  segments:
198
197
  - 0
199
198
  version: "0"