google-v3-geocoder 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/Gemfile +13 -0
- data/Gemfile.lock +23 -0
- data/LICENSE.txt +20 -0
- data/README +1 -0
- data/README.rdoc +19 -0
- data/Rakefile +44 -0
- data/VERSION +1 -0
- data/lib/google-v3-geocoder.rb +1 -0
- data/lib/google_v3_geocoder.rb +1 -0
- data/lib/google_v3_geocoder/geocoders.rb +125 -0
- data/test/.google_v3_geocoder_test.rb.swp +0 -0
- data/test/.helper.rb.swp +0 -0
- data/test/google_v3_geocoder_test.rb +278 -0
- data/test/test_helper.rb +18 -0
- metadata +162 -0
data/.document
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
geokit (1.5.0)
|
5
|
+
git (1.2.5)
|
6
|
+
jeweler (1.5.2)
|
7
|
+
bundler (~> 1.0.0)
|
8
|
+
git (>= 1.2.5)
|
9
|
+
rake
|
10
|
+
json (1.4.6)
|
11
|
+
mocha (0.9.10)
|
12
|
+
rake
|
13
|
+
rake (0.8.7)
|
14
|
+
|
15
|
+
PLATFORMS
|
16
|
+
ruby
|
17
|
+
|
18
|
+
DEPENDENCIES
|
19
|
+
bundler (~> 1.0.0)
|
20
|
+
geokit (>= 1.5.0)
|
21
|
+
jeweler (~> 1.5.2)
|
22
|
+
json
|
23
|
+
mocha (>= 0.9.9)
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Andrew La Motte-Mitchell
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
update
|
data/README.rdoc
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
= google-v3-geocoder
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Contributing to google-v3-geocoder
|
6
|
+
|
7
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
8
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
9
|
+
* Fork the project
|
10
|
+
* Start a feature/bugfix branch
|
11
|
+
* Commit and push until you are happy with your contribution
|
12
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
13
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2011 Andrew La Motte-Mitchell. See LICENSE.txt for
|
18
|
+
further details.
|
19
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
|
4
|
+
begin
|
5
|
+
Bundler.setup(:default, :development)
|
6
|
+
rescue Bundler::BundlerError => e
|
7
|
+
$stderr.puts e.message
|
8
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
9
|
+
exit e.status_code
|
10
|
+
end
|
11
|
+
require 'rake'
|
12
|
+
|
13
|
+
require 'jeweler'
|
14
|
+
Jeweler::Tasks.new do |gem|
|
15
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
16
|
+
gem.name = "google-v3-geocoder"
|
17
|
+
gem.homepage = "http://github.com/startupseven/google-v3-geocoder"
|
18
|
+
gem.license = "MIT"
|
19
|
+
gem.summary = %Q{Geokit::Geocoder subclass for interacting with Google's v3 API}
|
20
|
+
gem.description = %Q{Geokit::Geocoder subclass for interacting with Google's v3 API <http://code.google.com/apis/maps/documentation/geocoding/>}
|
21
|
+
gem.email = "developers@tello.com"
|
22
|
+
gem.authors = ["Andrew La Motte-Mitchell", "Tyler Wolf"]
|
23
|
+
gem.add_runtime_dependency "geokit", ">=1.5.0"
|
24
|
+
end
|
25
|
+
Jeweler::RubygemsDotOrgTasks.new
|
26
|
+
|
27
|
+
require 'rake/testtask'
|
28
|
+
Rake::TestTask.new(:test) do |test|
|
29
|
+
test.libs << 'lib' << 'test'
|
30
|
+
test.pattern = 'test/**/*test.rb'
|
31
|
+
test.verbose = true
|
32
|
+
end
|
33
|
+
|
34
|
+
task :default => :test
|
35
|
+
|
36
|
+
require 'rake/rdoctask'
|
37
|
+
Rake::RDocTask.new do |rdoc|
|
38
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
39
|
+
|
40
|
+
rdoc.rdoc_dir = 'rdoc'
|
41
|
+
rdoc.title = "google-v3-geocoder #{version}"
|
42
|
+
rdoc.rdoc_files.include('README*')
|
43
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
44
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.0.0
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'google_v3_geocoder'
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'google_v3_geocoder/geocoders'
|
@@ -0,0 +1,125 @@
|
|
1
|
+
require 'geokit'
|
2
|
+
require 'geokit/geocoders.rb'
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
module Geokit
|
6
|
+
module Geocoders
|
7
|
+
class GoogleV3Geocoder < Geocoder
|
8
|
+
private
|
9
|
+
|
10
|
+
def self.do_geocode(address, options = {})
|
11
|
+
geo_url = self.get_url(address, options)
|
12
|
+
logger.debug "Making Geocode request to: #{geo_url}"
|
13
|
+
res = self.call_geocoder_service(geo_url)
|
14
|
+
|
15
|
+
return GeoLoc.new if !res.is_a?(Net::HTTPSuccess)
|
16
|
+
json = res.body
|
17
|
+
logger.debug "Google V3 geocoding. Address: #{address}. Result: #{json}"
|
18
|
+
return self.convert_json_to_geoloc(json)
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.get_url(address, options={})
|
22
|
+
bias = options[:bias] || ''
|
23
|
+
address_str = address.is_a?(GeoLoc) ? address.to_geocodeable_s : address
|
24
|
+
return "http://maps.googleapis.com/maps/api/geocode/json?sensor=false&address=#{Geokit::Inflector::url_escape(address_str)}®ion=#{bias.to_s.downcase}"
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.convert_json_to_geoloc(json)
|
28
|
+
begin
|
29
|
+
data = JSON.parse(json)
|
30
|
+
rescue
|
31
|
+
logger.error "Could not parse JSON from Google: #{json}"
|
32
|
+
return GeoLoc.new
|
33
|
+
end
|
34
|
+
|
35
|
+
if data['status'] != "OK"
|
36
|
+
if data['status' ] == 'OVER_QUERY_LIMIT'
|
37
|
+
raise Geokit::TooManyQueriesError "Google returned OVER_QUERY_LIMIT: #{json}"
|
38
|
+
elsif data['status'] == 'ZERO_RESULTS'
|
39
|
+
logger.info "Found no results from google v3"
|
40
|
+
return GeoLoc.new
|
41
|
+
end
|
42
|
+
logger.error "Got an error from google, response: #{json}"
|
43
|
+
# Otherwise, we don't know what to do
|
44
|
+
return GeoLoc.new
|
45
|
+
end
|
46
|
+
|
47
|
+
begin
|
48
|
+
results = data['results']
|
49
|
+
geoloc = nil
|
50
|
+
results.each do |result|
|
51
|
+
extracted_geoloc = self.extract_location(result)
|
52
|
+
if geoloc.nil?
|
53
|
+
geoloc = extracted_geoloc
|
54
|
+
else
|
55
|
+
geoloc.all.push(extracted_geoloc)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
rescue Exception => e
|
59
|
+
logger.error "Encountered unexpected exception during google geocoding: #{e.inspect}"
|
60
|
+
return GeoLoc.new
|
61
|
+
end
|
62
|
+
|
63
|
+
return geoloc
|
64
|
+
end
|
65
|
+
|
66
|
+
def self.extract_location(result)
|
67
|
+
res = GeoLoc.new
|
68
|
+
res.provider = 'google_v3'
|
69
|
+
|
70
|
+
res.lat = result['geometry']['location']['lat']
|
71
|
+
res.lng = result['geometry']['location']['lng']
|
72
|
+
|
73
|
+
res.full_address = result['formatted_address']
|
74
|
+
|
75
|
+
street_number = nil
|
76
|
+
street_name = nil
|
77
|
+
|
78
|
+
result['address_components'].each do |component|
|
79
|
+
types = component['types']
|
80
|
+
|
81
|
+
if types.include?('street_number')
|
82
|
+
street_number = component['long_name']
|
83
|
+
end
|
84
|
+
|
85
|
+
if types.include?('route')
|
86
|
+
street_name = component['long_name']
|
87
|
+
end
|
88
|
+
|
89
|
+
if types.include?('country')
|
90
|
+
res.country = component['short_name']
|
91
|
+
res.country_code = component['short_name']
|
92
|
+
end
|
93
|
+
|
94
|
+
if types.include?('administrative_area_level_1')
|
95
|
+
res.state = component['short_name']
|
96
|
+
end
|
97
|
+
|
98
|
+
if types.include?('postal_code')
|
99
|
+
res.zip = component['long_name']
|
100
|
+
end
|
101
|
+
|
102
|
+
if types.include?('locality')
|
103
|
+
res.city = component['long_name']
|
104
|
+
end
|
105
|
+
|
106
|
+
if types.include?('locality')
|
107
|
+
res.zip = component['long_name']
|
108
|
+
end
|
109
|
+
|
110
|
+
end
|
111
|
+
res.street_address = [street_number, street_name].reject{|x| x.nil?}.join(" ")
|
112
|
+
|
113
|
+
# Set the bounds from the viewport
|
114
|
+
bounds = result['geometry']['viewport']
|
115
|
+
res.suggested_bounds = Bounds.normalize(
|
116
|
+
[bounds['southwest']['lat'], bounds['southwest']['lng']],
|
117
|
+
[bounds['northeast']['lat'], bounds['northeast']['lng']]
|
118
|
+
)
|
119
|
+
|
120
|
+
res.success = true
|
121
|
+
return res
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
Binary file
|
data/test/.helper.rb.swp
ADDED
Binary file
|
@@ -0,0 +1,278 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class GoogleV3GeocoderTest < Test::Unit::TestCase
|
4
|
+
include Geokit
|
5
|
+
|
6
|
+
GOOD_JSON = <<-JSON
|
7
|
+
{
|
8
|
+
"status": "OK",
|
9
|
+
"results": [ {
|
10
|
+
"types": [ "street_address" ],
|
11
|
+
"formatted_address": "1288 E Hillsdale Blvd, Foster City, CA 94404, USA",
|
12
|
+
"address_components": [ {
|
13
|
+
"long_name": "1288",
|
14
|
+
"short_name": "1288",
|
15
|
+
"types": [ "street_number" ]
|
16
|
+
}, {
|
17
|
+
"long_name": "E Hillsdale Blvd",
|
18
|
+
"short_name": "E Hillsdale Blvd",
|
19
|
+
"types": [ "route" ]
|
20
|
+
}, {
|
21
|
+
"long_name": "Foster City",
|
22
|
+
"short_name": "Foster City",
|
23
|
+
"types": [ "locality", "political" ]
|
24
|
+
}, {
|
25
|
+
"long_name": "San Mateo",
|
26
|
+
"short_name": "San Mateo",
|
27
|
+
"types": [ "administrative_area_level_3", "political" ]
|
28
|
+
}, {
|
29
|
+
"long_name": "San Mateo",
|
30
|
+
"short_name": "San Mateo",
|
31
|
+
"types": [ "administrative_area_level_2", "political" ]
|
32
|
+
}, {
|
33
|
+
"long_name": "California",
|
34
|
+
"short_name": "CA",
|
35
|
+
"types": [ "administrative_area_level_1", "political" ]
|
36
|
+
}, {
|
37
|
+
"long_name": "United States",
|
38
|
+
"short_name": "US",
|
39
|
+
"types": [ "country", "political" ]
|
40
|
+
}, {
|
41
|
+
"long_name": "94404",
|
42
|
+
"short_name": "94404",
|
43
|
+
"types": [ "postal_code" ]
|
44
|
+
} ],
|
45
|
+
"geometry": {
|
46
|
+
"location": {
|
47
|
+
"lat": 37.5684570,
|
48
|
+
"lng": -122.2660670
|
49
|
+
},
|
50
|
+
"location_type": "ROOFTOP",
|
51
|
+
"viewport": {
|
52
|
+
"southwest": {
|
53
|
+
"lat": 37.5653094,
|
54
|
+
"lng": -122.2692146
|
55
|
+
},
|
56
|
+
"northeast": {
|
57
|
+
"lat": 37.5716046,
|
58
|
+
"lng": -122.2629194
|
59
|
+
}
|
60
|
+
}
|
61
|
+
}
|
62
|
+
} ]
|
63
|
+
}
|
64
|
+
JSON
|
65
|
+
|
66
|
+
def test_get_url_adds_bias_if_set
|
67
|
+
bias = 'thefreakingus'
|
68
|
+
result = Geokit::Geocoders::GoogleV3Geocoder.send :get_url, 'address', :bias => bias
|
69
|
+
assert_match /®ion=#{bias}/, result
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_get_url_escapes_address
|
73
|
+
address = '123 hotel street'
|
74
|
+
result = Geokit::Geocoders::GoogleV3Geocoder.send :get_url, address
|
75
|
+
assert_match /&address=#{Regexp.escape(Geokit::Inflector::url_escape(address))}/, result
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_convert_json_to_geoloc_extracts_result_from_json
|
79
|
+
result = Geokit::Geocoders::GoogleV3Geocoder.send :convert_json_to_geoloc, GOOD_JSON
|
80
|
+
assert result.success
|
81
|
+
assert_equal 1, result.all.size
|
82
|
+
assert_equal '1288 E Hillsdale Blvd, Foster City, CA 94404, USA', result.full_address
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_convert_json_to_geoloc_handles_empty_result_set
|
86
|
+
empty_json = '{"status": "ZERO_RESULTS","results": [ ]}'
|
87
|
+
result = Geokit::Geocoders::GoogleV3Geocoder.send :convert_json_to_geoloc, empty_json
|
88
|
+
assert !result.success
|
89
|
+
assert_equal 1, result.all.size
|
90
|
+
assert_nil result.lat
|
91
|
+
assert_nil result.lng
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_convert_json_to_geoloc_calls_extract_location
|
95
|
+
expected_geoloc = GeoLoc.new
|
96
|
+
expected_geoloc.city = "SOME City"
|
97
|
+
Geokit::Geocoders::GoogleV3Geocoder.expects(:extract_location).returns expected_geoloc
|
98
|
+
|
99
|
+
result = Geokit::Geocoders::GoogleV3Geocoder.send :convert_json_to_geoloc, GOOD_JSON
|
100
|
+
assert_equal result, expected_geoloc
|
101
|
+
end
|
102
|
+
|
103
|
+
def test_convert_json_to_handles_multiple_results
|
104
|
+
address1 = 'add1'
|
105
|
+
address2 = 'add2'
|
106
|
+
|
107
|
+
input_data = {
|
108
|
+
"status" => "OK",
|
109
|
+
"results" =>
|
110
|
+
[
|
111
|
+
{
|
112
|
+
"types" => [ "street_address" ],
|
113
|
+
"formatted_address" => address1,
|
114
|
+
"address_components" => [],
|
115
|
+
"geometry" => {
|
116
|
+
"location"=> {
|
117
|
+
"lat"=> 35.58032,
|
118
|
+
"lng"=> -122.2660670
|
119
|
+
},
|
120
|
+
"location_type"=> "ROOFTOP",
|
121
|
+
"viewport"=> {
|
122
|
+
"southwest"=> {
|
123
|
+
"lat"=> 37.5653094,
|
124
|
+
"lng"=> -122.2692146,
|
125
|
+
},
|
126
|
+
"northeast"=> {
|
127
|
+
"lat"=> 37.5716046,
|
128
|
+
"lng"=> -122.2629194
|
129
|
+
}
|
130
|
+
},
|
131
|
+
},
|
132
|
+
},
|
133
|
+
{
|
134
|
+
"types" => [ "street_address" ],
|
135
|
+
"formatted_address" => address2,
|
136
|
+
"address_components" => [],
|
137
|
+
"geometry" => {
|
138
|
+
"location"=> {
|
139
|
+
"lat"=> 35.58032,
|
140
|
+
"lng"=> -122.2660670
|
141
|
+
},
|
142
|
+
"location_type"=> "ROOFTOP",
|
143
|
+
"viewport"=> {
|
144
|
+
"southwest"=> {
|
145
|
+
"lat"=> 37.5653094,
|
146
|
+
"lng"=> -122.2692146,
|
147
|
+
},
|
148
|
+
"northeast"=> {
|
149
|
+
"lat"=> 37.5716046,
|
150
|
+
"lng"=> -122.2629194
|
151
|
+
}
|
152
|
+
},
|
153
|
+
},
|
154
|
+
}
|
155
|
+
]
|
156
|
+
}
|
157
|
+
result = Geokit::Geocoders::GoogleV3Geocoder.send :convert_json_to_geoloc, input_data.to_json
|
158
|
+
assert result.success
|
159
|
+
assert_equal 2, result.all.size
|
160
|
+
assert_equal address1, result.all[0].full_address
|
161
|
+
assert_equal address2, result.all[1].full_address
|
162
|
+
end
|
163
|
+
|
164
|
+
def test_extract_location_extracts_result_from_json
|
165
|
+
data = JSON.parse(GOOD_JSON)['results'][0]
|
166
|
+
result = Geokit::Geocoders::GoogleV3Geocoder.send :extract_location, data
|
167
|
+
assert_equal 'Foster City', result.city
|
168
|
+
assert_equal 'CA', result.state
|
169
|
+
assert_equal '94404', result.zip
|
170
|
+
assert_equal 'US', result.country
|
171
|
+
assert_equal 'US', result.country_code
|
172
|
+
assert_equal '1288 E Hillsdale Blvd', result.street_address
|
173
|
+
assert_equal '1288 E Hillsdale Blvd, Foster City, CA 94404, USA', result.full_address
|
174
|
+
assert_equal 37.5653094, result.suggested_bounds.sw.lat
|
175
|
+
assert_equal -122.2692146, result.suggested_bounds.sw.lng
|
176
|
+
assert_equal 37.5716046, result.suggested_bounds.ne.lat
|
177
|
+
assert_equal -122.2629194, result.suggested_bounds.ne.lng
|
178
|
+
end
|
179
|
+
|
180
|
+
def test_extract_joins_street_address_with_no_number
|
181
|
+
route_name = 'Foo'
|
182
|
+
data =
|
183
|
+
{
|
184
|
+
"types" => [ "street_address" ],
|
185
|
+
"formatted_address" => 'address1',
|
186
|
+
"address_components" => [
|
187
|
+
{'types' => ['route'], 'long_name' => route_name, 'short_name' => route_name}
|
188
|
+
],
|
189
|
+
"geometry" => {
|
190
|
+
"location"=> {
|
191
|
+
"lat"=> 35.58032,
|
192
|
+
"lng"=> -122.2660670
|
193
|
+
},
|
194
|
+
"location_type"=> "ROOFTOP",
|
195
|
+
"viewport"=> {
|
196
|
+
"southwest"=> {
|
197
|
+
"lat"=> 37.5653094,
|
198
|
+
"lng"=> -122.2692146,
|
199
|
+
},
|
200
|
+
"northeast"=> {
|
201
|
+
"lat"=> 37.5716046,
|
202
|
+
"lng"=> -122.2629194
|
203
|
+
}
|
204
|
+
},
|
205
|
+
},
|
206
|
+
}
|
207
|
+
|
208
|
+
result = Geokit::Geocoders::GoogleV3Geocoder.send :extract_location, data
|
209
|
+
assert_equal route_name, result.street_address
|
210
|
+
end
|
211
|
+
|
212
|
+
def test_extract_joins_street_address_with_no_route
|
213
|
+
number = '358'
|
214
|
+
data =
|
215
|
+
{
|
216
|
+
"types" => [ "street_address" ],
|
217
|
+
"formatted_address" => 'address1',
|
218
|
+
"address_components" => [
|
219
|
+
{'types' => ['street_number'], 'long_name' => number, 'short_name' => number},
|
220
|
+
],
|
221
|
+
"geometry" => {
|
222
|
+
"location"=> {
|
223
|
+
"lat"=> 35.58032,
|
224
|
+
"lng"=> -122.2660670
|
225
|
+
},
|
226
|
+
"location_type"=> "ROOFTOP",
|
227
|
+
"viewport"=> {
|
228
|
+
"southwest"=> {
|
229
|
+
"lat"=> 37.5653094,
|
230
|
+
"lng"=> -122.2692146,
|
231
|
+
},
|
232
|
+
"northeast"=> {
|
233
|
+
"lat"=> 37.5716046,
|
234
|
+
"lng"=> -122.2629194
|
235
|
+
}
|
236
|
+
},
|
237
|
+
},
|
238
|
+
}
|
239
|
+
|
240
|
+
result = Geokit::Geocoders::GoogleV3Geocoder.send :extract_location, data
|
241
|
+
assert_equal number, result.street_address
|
242
|
+
end
|
243
|
+
|
244
|
+
def test_extract_joins_street_address_with_number_and_route
|
245
|
+
route_name = 'Foo'
|
246
|
+
number = '3854'
|
247
|
+
data =
|
248
|
+
{
|
249
|
+
"types" => [ "street_address" ],
|
250
|
+
"formatted_address" => 'address1',
|
251
|
+
"address_components" => [
|
252
|
+
{'types' => ['route'], 'long_name' => route_name, 'short_name' => route_name},
|
253
|
+
{'types' => ['street_number'], 'long_name' => number, 'short_name' => number}
|
254
|
+
],
|
255
|
+
"geometry" => {
|
256
|
+
"location"=> {
|
257
|
+
"lat"=> 35.58032,
|
258
|
+
"lng"=> -122.2660670
|
259
|
+
},
|
260
|
+
"location_type"=> "ROOFTOP",
|
261
|
+
"viewport"=> {
|
262
|
+
"southwest"=> {
|
263
|
+
"lat"=> 37.5653094,
|
264
|
+
"lng"=> -122.2692146,
|
265
|
+
},
|
266
|
+
"northeast"=> {
|
267
|
+
"lat"=> 37.5716046,
|
268
|
+
"lng"=> -122.2629194
|
269
|
+
}
|
270
|
+
},
|
271
|
+
},
|
272
|
+
}
|
273
|
+
|
274
|
+
result = Geokit::Geocoders::GoogleV3Geocoder.send :extract_location, data
|
275
|
+
assert_equal number + ' ' + route_name, result.street_address
|
276
|
+
end
|
277
|
+
|
278
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'test/unit'
|
11
|
+
require 'mocha'
|
12
|
+
|
13
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
14
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
15
|
+
require 'google-v3-geocoder'
|
16
|
+
|
17
|
+
class Test::Unit::TestCase
|
18
|
+
end
|
metadata
ADDED
@@ -0,0 +1,162 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: google-v3-geocoder
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 23
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
- 0
|
10
|
+
version: 1.0.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Andrew La Motte-Mitchell
|
14
|
+
- Tyler Wolf
|
15
|
+
autorequire:
|
16
|
+
bindir: bin
|
17
|
+
cert_chain: []
|
18
|
+
|
19
|
+
date: 2011-02-11 00:00:00 -08:00
|
20
|
+
default_executable:
|
21
|
+
dependencies:
|
22
|
+
- !ruby/object:Gem::Dependency
|
23
|
+
prerelease: false
|
24
|
+
type: :runtime
|
25
|
+
name: geokit
|
26
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
27
|
+
none: false
|
28
|
+
requirements:
|
29
|
+
- - ">="
|
30
|
+
- !ruby/object:Gem::Version
|
31
|
+
hash: 3
|
32
|
+
segments:
|
33
|
+
- 1
|
34
|
+
- 5
|
35
|
+
- 0
|
36
|
+
version: 1.5.0
|
37
|
+
requirement: *id001
|
38
|
+
- !ruby/object:Gem::Dependency
|
39
|
+
prerelease: false
|
40
|
+
type: :runtime
|
41
|
+
name: json
|
42
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
43
|
+
none: false
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
hash: 3
|
48
|
+
segments:
|
49
|
+
- 0
|
50
|
+
version: "0"
|
51
|
+
requirement: *id002
|
52
|
+
- !ruby/object:Gem::Dependency
|
53
|
+
prerelease: false
|
54
|
+
type: :development
|
55
|
+
name: bundler
|
56
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
hash: 23
|
62
|
+
segments:
|
63
|
+
- 1
|
64
|
+
- 0
|
65
|
+
- 0
|
66
|
+
version: 1.0.0
|
67
|
+
requirement: *id003
|
68
|
+
- !ruby/object:Gem::Dependency
|
69
|
+
prerelease: false
|
70
|
+
type: :development
|
71
|
+
name: jeweler
|
72
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
hash: 7
|
78
|
+
segments:
|
79
|
+
- 1
|
80
|
+
- 5
|
81
|
+
- 2
|
82
|
+
version: 1.5.2
|
83
|
+
requirement: *id004
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
prerelease: false
|
86
|
+
type: :runtime
|
87
|
+
name: geokit
|
88
|
+
version_requirements: &id005 !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
hash: 3
|
94
|
+
segments:
|
95
|
+
- 1
|
96
|
+
- 5
|
97
|
+
- 0
|
98
|
+
version: 1.5.0
|
99
|
+
requirement: *id005
|
100
|
+
description: Geokit::Geocoder subclass for interacting with Google's v3 API <http://code.google.com/apis/maps/documentation/geocoding/>
|
101
|
+
email: developers@tello.com
|
102
|
+
executables: []
|
103
|
+
|
104
|
+
extensions: []
|
105
|
+
|
106
|
+
extra_rdoc_files:
|
107
|
+
- LICENSE.txt
|
108
|
+
- README
|
109
|
+
- README.rdoc
|
110
|
+
files:
|
111
|
+
- .document
|
112
|
+
- Gemfile
|
113
|
+
- Gemfile.lock
|
114
|
+
- LICENSE.txt
|
115
|
+
- README
|
116
|
+
- README.rdoc
|
117
|
+
- Rakefile
|
118
|
+
- VERSION
|
119
|
+
- lib/google-v3-geocoder.rb
|
120
|
+
- lib/google_v3_geocoder.rb
|
121
|
+
- lib/google_v3_geocoder/geocoders.rb
|
122
|
+
- test/.google_v3_geocoder_test.rb.swp
|
123
|
+
- test/.helper.rb.swp
|
124
|
+
- test/google_v3_geocoder_test.rb
|
125
|
+
- test/test_helper.rb
|
126
|
+
has_rdoc: true
|
127
|
+
homepage: http://github.com/startupseven/google-v3-geocoder
|
128
|
+
licenses:
|
129
|
+
- MIT
|
130
|
+
post_install_message:
|
131
|
+
rdoc_options: []
|
132
|
+
|
133
|
+
require_paths:
|
134
|
+
- lib
|
135
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
136
|
+
none: false
|
137
|
+
requirements:
|
138
|
+
- - ">="
|
139
|
+
- !ruby/object:Gem::Version
|
140
|
+
hash: 3
|
141
|
+
segments:
|
142
|
+
- 0
|
143
|
+
version: "0"
|
144
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
145
|
+
none: false
|
146
|
+
requirements:
|
147
|
+
- - ">="
|
148
|
+
- !ruby/object:Gem::Version
|
149
|
+
hash: 3
|
150
|
+
segments:
|
151
|
+
- 0
|
152
|
+
version: "0"
|
153
|
+
requirements: []
|
154
|
+
|
155
|
+
rubyforge_project:
|
156
|
+
rubygems_version: 1.3.7
|
157
|
+
signing_key:
|
158
|
+
specification_version: 3
|
159
|
+
summary: Geokit::Geocoder subclass for interacting with Google's v3 API
|
160
|
+
test_files:
|
161
|
+
- test/google_v3_geocoder_test.rb
|
162
|
+
- test/test_helper.rb
|