geokit 1.8.4 → 1.8.5
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/.travis.yml +4 -6
- data/CHANGELOG.md +9 -0
- data/README.markdown +27 -3
- data/fixtures/vcr_cassettes/bing_au.yml +86 -0
- data/fixtures/vcr_cassettes/bing_full.yml +61 -68
- data/fixtures/vcr_cassettes/bing_full_au.yml +43 -39
- data/fixtures/vcr_cassettes/bing_full_de.yml +43 -39
- data/fixtures/vcr_cassettes/fcc_reverse_geocode.yml +9 -7
- data/fixtures/vcr_cassettes/geocodio_geocode.yml +43 -0
- data/fixtures/vcr_cassettes/google_city.yml +8 -6
- data/fixtures/vcr_cassettes/google_country_code_biased_result.yml +27 -25
- data/fixtures/vcr_cassettes/google_full.yml +13 -16
- data/fixtures/vcr_cassettes/google_full_short.yml +8 -6
- data/fixtures/vcr_cassettes/google_language_response_fr.yml +23 -21
- data/fixtures/vcr_cassettes/google_multi.yml +7 -5
- data/fixtures/vcr_cassettes/google_reverse_madrid.yml +281 -278
- data/fixtures/vcr_cassettes/google_reverse_madrid_es.yml +26 -32
- data/fixtures/vcr_cassettes/map_quest_full.yml +53 -0
- data/fixtures/vcr_cassettes/map_quest_reverse_madrid.yml +52 -0
- data/fixtures/vcr_cassettes/ripe_geocode_45.yml +45 -0
- data/fixtures/vcr_cassettes/yahoo_city.yml +1 -1
- data/fixtures/vcr_cassettes/yahoo_full.yml +1 -1
- data/fixtures/vcr_cassettes/yahoo_no_results.yml +1 -1
- data/lib/geokit/geocoders.rb +16 -1
- data/lib/geokit/geocoders/bing.rb +22 -18
- data/lib/geokit/geocoders/fcc.rb +2 -1
- data/lib/geokit/geocoders/geocodio.rb +59 -0
- data/lib/geokit/geocoders/google.rb +7 -3
- data/lib/geokit/geocoders/mapquest.rb +3 -2
- data/lib/geokit/geocoders/ripe.rb +8 -5
- data/lib/geokit/geocoders/yahoo.rb +2 -1
- data/lib/geokit/lat_lng.rb +13 -3
- data/lib/geokit/mappable.rb +13 -0
- data/lib/geokit/multi_geocoder.rb +13 -2
- data/lib/geokit/net_adapter/net_http.rb +6 -1
- data/lib/geokit/version.rb +1 -1
- data/test/helper.rb +2 -1
- data/test/test_bing_geocoder.rb +23 -3
- data/test/test_fcc_geocoder.rb +1 -1
- data/test/test_geocodio_geocoder.rb +33 -0
- data/test/test_google_geocoder.rb +31 -17
- data/test/test_latlng.rb +18 -0
- data/test/test_map_quest.rb +56 -0
- data/test/test_multi_geocoder.rb +7 -0
- data/test/test_ripe_geocoder.rb +19 -12
- data/test/test_yahoo_geocoder.rb +7 -7
- metadata +12 -8
@@ -1,7 +1,8 @@
|
|
1
1
|
module Geokit
|
2
2
|
module Geocoders
|
3
3
|
class GoogleGeocoder < Geocoder
|
4
|
-
config :client_id, :cryptographic_key, :channel
|
4
|
+
config :client_id, :cryptographic_key, :channel, :api_key
|
5
|
+
self.secure = true
|
5
6
|
|
6
7
|
private
|
7
8
|
# ==== OPTIONS
|
@@ -62,9 +63,12 @@ module Geokit
|
|
62
63
|
channel_string = channel ? "&channel=#{channel}" : ''
|
63
64
|
urlToSign = query_string + "&client=#{client_id}" + channel_string
|
64
65
|
signature = sign_gmap_bus_api_url(urlToSign, cryptographic_key)
|
65
|
-
"
|
66
|
+
"#{protocol}://maps.googleapis.com" + urlToSign + "&signature=#{signature}"
|
67
|
+
elsif api_key
|
68
|
+
url_with_key = query_string + "&key=#{api_key}"
|
69
|
+
"#{protocol}://maps.googleapis.com" + url_with_key
|
66
70
|
else
|
67
|
-
"
|
71
|
+
"#{protocol}://maps.google.com" + query_string
|
68
72
|
end
|
69
73
|
end
|
70
74
|
|
@@ -4,20 +4,21 @@ module Geokit
|
|
4
4
|
# contain a MapQuest API key. Conforms to the interface set by the Geocoder class.
|
5
5
|
class MapQuestGeocoder < Geocoder
|
6
6
|
config :key
|
7
|
+
self.secure = true
|
7
8
|
|
8
9
|
private
|
9
10
|
|
10
11
|
# Template method which does the reverse-geocode lookup.
|
11
12
|
def self.do_reverse_geocode(latlng)
|
12
13
|
latlng=LatLng.normalize(latlng)
|
13
|
-
url = "
|
14
|
+
url = "#{protocol}://www.mapquestapi.com/geocoding/v1/reverse?key=#{key}&location=#{latlng.lat},#{latlng.lng}"
|
14
15
|
process :json, url
|
15
16
|
end
|
16
17
|
|
17
18
|
# Template method which does the geocode lookup.
|
18
19
|
def self.do_geocode(address)
|
19
20
|
address_str = address.is_a?(GeoLoc) ? address.to_geocodeable_s : address
|
20
|
-
url = "
|
21
|
+
url = "#{protocol}://www.mapquestapi.com/geocoding/v1/address?key=#{key}&location=#{Geokit::Inflector::url_escape(address_str)}"
|
21
22
|
process :json, url
|
22
23
|
end
|
23
24
|
|
@@ -2,6 +2,7 @@ module Geokit
|
|
2
2
|
module Geocoders
|
3
3
|
# Provides geocoding based upon an IP address. The underlying web service is geoplugin.net
|
4
4
|
class RipeGeocoder < BaseIpGeocoder
|
5
|
+
self.secure = false # supports HTTPS, but Net::HTTPS doesn't like the server
|
5
6
|
private
|
6
7
|
|
7
8
|
def self.do_geocode(ip)
|
@@ -9,17 +10,19 @@ module Geokit
|
|
9
10
|
end
|
10
11
|
|
11
12
|
def self.submit_url(ip)
|
12
|
-
"
|
13
|
+
"#{protocol}://stat.ripe.net/data/geoloc/data.json?resource=#{ip}"
|
13
14
|
end
|
14
15
|
|
15
16
|
def self.parse_json(json)
|
16
17
|
loc = new_loc
|
17
18
|
data = json['data']['locations'][0]
|
18
19
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
20
|
+
if data
|
21
|
+
loc.lat = data['latitude']
|
22
|
+
loc.lng = data['longitude']
|
23
|
+
set_address_components(data, loc)
|
24
|
+
loc.success = data && (data['status_code'] == 200)
|
25
|
+
end
|
23
26
|
loc
|
24
27
|
end
|
25
28
|
|
@@ -4,6 +4,7 @@ module Geokit
|
|
4
4
|
# contain a Yahoo API key. Conforms to the interface set by the Geocoder class.
|
5
5
|
class YahooGeocoder < Geocoder
|
6
6
|
config :key, :secret
|
7
|
+
self.secure = true
|
7
8
|
|
8
9
|
private
|
9
10
|
def self.submit_url(address)
|
@@ -13,7 +14,7 @@ module Geokit
|
|
13
14
|
o = OauthUtil.new
|
14
15
|
o.consumer_key = key
|
15
16
|
o.consumer_secret = secret
|
16
|
-
base = "
|
17
|
+
base = "#{protocol}://yboss.yahooapis.com/geo/placefinder"
|
17
18
|
parsed_url = URI.parse("#{base}#{query_string}")
|
18
19
|
"#{base}?#{o.sign(parsed_url).query_string}"
|
19
20
|
end
|
data/lib/geokit/lat_lng.rb
CHANGED
@@ -32,6 +32,16 @@ module Geokit
|
|
32
32
|
"#{lat},#{lng}"
|
33
33
|
end
|
34
34
|
|
35
|
+
# returns latitude as [ degree, minute, second ] array
|
36
|
+
def lat_dms
|
37
|
+
self.class.decimal_to_dms(lat)
|
38
|
+
end
|
39
|
+
|
40
|
+
# returns longitude as [ degree, minute, second ] array
|
41
|
+
def lng_dms
|
42
|
+
self.class.decimal_to_dms(lng)
|
43
|
+
end
|
44
|
+
|
35
45
|
#returns a string with comma-separated lat,lng values
|
36
46
|
def to_s
|
37
47
|
ll
|
@@ -70,7 +80,7 @@ module Geokit
|
|
70
80
|
# 4) an array in the format [37.1234,-129.1234]
|
71
81
|
# 5) a LatLng or GeoLoc (which is just passed through as-is)
|
72
82
|
# 6) anything responding to to_lat_lng -- a LatLng will be extracted from it
|
73
|
-
def self.normalize(thing,other=nil)
|
83
|
+
def self.normalize(thing, other=nil)
|
74
84
|
return Geokit::LatLng.new(thing, other) if other
|
75
85
|
|
76
86
|
case thing
|
@@ -78,7 +88,7 @@ module Geokit
|
|
78
88
|
from_string(thing)
|
79
89
|
when Array
|
80
90
|
thing.size == 2 or raise ArgumentError.new("Must initialize with an Array with both latitude and longitude")
|
81
|
-
Geokit::LatLng.new(thing[0],thing[1])
|
91
|
+
Geokit::LatLng.new(thing[0], thing[1])
|
82
92
|
when LatLng # will also be true for GeoLocs
|
83
93
|
thing
|
84
94
|
else
|
@@ -93,7 +103,7 @@ module Geokit
|
|
93
103
|
def self.from_string(thing)
|
94
104
|
thing.strip!
|
95
105
|
if match=thing.match(/(\-?\d+\.?\d*)[, ] ?(\-?\d+\.?\d*)$/)
|
96
|
-
Geokit::LatLng.new(match[1],match[2])
|
106
|
+
Geokit::LatLng.new(match[1], match[2])
|
97
107
|
else
|
98
108
|
res = Geokit::Geocoders::MultiGeocoder.geocode(thing)
|
99
109
|
return res if res.success?
|
data/lib/geokit/mappable.rb
CHANGED
@@ -127,6 +127,19 @@ module Geokit
|
|
127
127
|
raise Geokit::Geocoders::GeocodeError
|
128
128
|
end
|
129
129
|
|
130
|
+
# Given a decimal degree like -87.660333
|
131
|
+
# return a 3-element array like [ -87, 39, 37.198... ]
|
132
|
+
def decimal_to_dms(deg)
|
133
|
+
return false unless deg.is_a?(Numeric)
|
134
|
+
# seconds is 0...3599.999, representing the entire fractional part.
|
135
|
+
seconds = (deg.abs % 1.0) * 3600.0
|
136
|
+
[
|
137
|
+
deg.to_i, # degrees as positive or negative integer
|
138
|
+
(seconds / 60).to_i, # minutes as positive integer
|
139
|
+
(seconds % 60) # seconds as positive float
|
140
|
+
]
|
141
|
+
end
|
142
|
+
|
130
143
|
protected
|
131
144
|
|
132
145
|
def deg2rad(degrees)
|
@@ -23,8 +23,7 @@ module Geokit
|
|
23
23
|
# The failover approach is crucial for production-grade apps, but is rarely used.
|
24
24
|
# 98% of your geocoding calls will be successful with the first call
|
25
25
|
def self.do_geocode(address, *args)
|
26
|
-
|
27
|
-
provider_order = geocode_ip ? Geokit::Geocoders::ip_provider_order : Geokit::Geocoders::provider_order
|
26
|
+
provider_order = provider_order_for(address, args)
|
28
27
|
|
29
28
|
provider_order.each do |provider|
|
30
29
|
klass = geocoder(provider)
|
@@ -59,6 +58,18 @@ module Geokit
|
|
59
58
|
def self.geocoder(provider)
|
60
59
|
Geokit::Geocoders.const_get "#{Geokit::Inflector::camelize(provider.to_s)}Geocoder"
|
61
60
|
end
|
61
|
+
|
62
|
+
def self.provider_order_for(address, args)
|
63
|
+
if args.last.is_a?(Hash) && args.last.key?(:provider_order)
|
64
|
+
args.last.delete(:provider_order)
|
65
|
+
else
|
66
|
+
if /^(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})$/.match(address)
|
67
|
+
Geokit::Geocoders::ip_provider_order
|
68
|
+
else
|
69
|
+
Geokit::Geocoders::provider_order
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
62
73
|
end
|
63
74
|
end
|
64
75
|
end
|
@@ -10,7 +10,12 @@ module Geokit
|
|
10
10
|
proxy_uri = URI.parse(proxy_uri_string)
|
11
11
|
net_http_args += [proxy_uri.host, proxy_uri.port, proxy_uri.user, proxy_uri.password]
|
12
12
|
end
|
13
|
-
Net::HTTP::new(*net_http_args)
|
13
|
+
http = Net::HTTP::new(*net_http_args)
|
14
|
+
if uri.scheme == 'https'
|
15
|
+
http.use_ssl = true
|
16
|
+
http.verify_mode = Geokit::Geocoders.ssl_verify_mode
|
17
|
+
end
|
18
|
+
http.start { |http| http.request(req) }
|
14
19
|
end
|
15
20
|
|
16
21
|
def self.success?(response)
|
data/lib/geokit/version.rb
CHANGED
data/test/helper.rb
CHANGED
@@ -11,7 +11,7 @@ end
|
|
11
11
|
require 'geoip'
|
12
12
|
|
13
13
|
if ENV['COVERAGE']
|
14
|
-
COVERAGE_THRESHOLD =
|
14
|
+
COVERAGE_THRESHOLD = 95
|
15
15
|
require 'simplecov'
|
16
16
|
require 'simplecov-rcov'
|
17
17
|
require 'coveralls'
|
@@ -110,6 +110,7 @@ class BaseGeocoderTest < Test::Unit::TestCase #:nodoc: all
|
|
110
110
|
|
111
111
|
# Defines common test fixtures.
|
112
112
|
def setup
|
113
|
+
Geokit::Geocoders::request_timeout = 10
|
113
114
|
@address = 'San Francisco, CA'
|
114
115
|
@full_address = '100 Spear St, San Francisco, CA, 94105-1522, US'
|
115
116
|
@full_address_short_zip = '100 Spear St, San Francisco, CA, 94105, US'
|
data/test/test_bing_geocoder.rb
CHANGED
@@ -16,7 +16,7 @@ class BingGeocoderTest < BaseGeocoderTest #:nodoc: all
|
|
16
16
|
def test_bing_full_address
|
17
17
|
VCR.use_cassette('bing_full') do
|
18
18
|
key = Geokit::Geocoders::BingGeocoder.key
|
19
|
-
url = "
|
19
|
+
url = "https://dev.virtualearth.net/REST/v1/Locations/#{URI.escape(@full_address)}?key=#{key}&o=xml"
|
20
20
|
res = Geokit::Geocoders::BingGeocoder.geocode(@full_address)
|
21
21
|
assert_equal "CA", res.state
|
22
22
|
assert_equal "San Francisco", res.city
|
@@ -32,7 +32,7 @@ class BingGeocoderTest < BaseGeocoderTest #:nodoc: all
|
|
32
32
|
address = '440 King William Street, Adelaide, Australia'
|
33
33
|
VCR.use_cassette('bing_full_au') do
|
34
34
|
key = Geokit::Geocoders::BingGeocoder.key
|
35
|
-
url = "
|
35
|
+
url = "https://dev.virtualearth.net/REST/v1/Locations/#{URI.escape(address)}?key=#{key}&o=xml"
|
36
36
|
res = Geokit::Geocoders::BingGeocoder.geocode(address)
|
37
37
|
assert_equal "SA", res.state
|
38
38
|
assert_equal "Adelaide", res.city
|
@@ -49,7 +49,7 @@ class BingGeocoderTest < BaseGeocoderTest #:nodoc: all
|
|
49
49
|
address = "Platz der Republik 1, 11011 Berlin, Germany"
|
50
50
|
VCR.use_cassette('bing_full_de') do
|
51
51
|
key = Geokit::Geocoders::BingGeocoder.key
|
52
|
-
url = "
|
52
|
+
url = "https://dev.virtualearth.net/REST/v1/Locations/#{URI.escape(address)}?key=#{key}&o=xml"
|
53
53
|
res = Geokit::Geocoders::BingGeocoder.geocode(address)
|
54
54
|
assert_equal "BE", res.state
|
55
55
|
assert_equal "Berlin", res.city
|
@@ -57,6 +57,26 @@ class BingGeocoderTest < BaseGeocoderTest #:nodoc: all
|
|
57
57
|
assert res.country == 'Germany'
|
58
58
|
assert_equal "Platz der Republik 1, 10557 Berlin", res.full_address
|
59
59
|
assert_equal "bing", res.provider
|
60
|
+
assert_equal 'address', res.precision
|
61
|
+
assert_equal 8, res.accuracy
|
62
|
+
assert_url url
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_bing_country
|
67
|
+
address = "Australia"
|
68
|
+
VCR.use_cassette('bing_au') do
|
69
|
+
key = Geokit::Geocoders::BingGeocoder.key
|
70
|
+
url = "https://dev.virtualearth.net/REST/v1/Locations/#{URI.escape(address)}?key=#{key}&o=xml"
|
71
|
+
res = Geokit::Geocoders::BingGeocoder.geocode(address)
|
72
|
+
assert_equal nil, res.state
|
73
|
+
assert_equal nil, res.city
|
74
|
+
assert_array_in_delta [-25.585, 134.504], res.to_a
|
75
|
+
assert res.country == 'Australia'
|
76
|
+
assert_equal 'Australia', res.full_address
|
77
|
+
assert_equal "bing", res.provider
|
78
|
+
assert_equal 'country', res.precision
|
79
|
+
assert_equal 8, res.accuracy
|
60
80
|
assert_url url
|
61
81
|
end
|
62
82
|
end
|
data/test/test_fcc_geocoder.rb
CHANGED
@@ -12,7 +12,7 @@ class FCCGeocoderTest < BaseGeocoderTest #:nodoc: all
|
|
12
12
|
|
13
13
|
def test_fcc_reverse_geocode
|
14
14
|
VCR.use_cassette('fcc_reverse_geocode') do
|
15
|
-
url = "
|
15
|
+
url = "https://data.fcc.gov/api/block/find?format=json&latitude=34.05&longitude=-118.25"
|
16
16
|
res = Geokit::Geocoders::FCCGeocoder.reverse_geocode(@la)
|
17
17
|
assert_url url
|
18
18
|
assert_equal res.country_code, 'US'
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'helper')
|
2
|
+
|
3
|
+
Geokit::Geocoders::GeocodioGeocoder.key = '723d41115152d224fd74727df34727c444537f7'
|
4
|
+
|
5
|
+
class GeocodioGeocoderTest < BaseGeocoderTest #:nodoc: all
|
6
|
+
def setup
|
7
|
+
super
|
8
|
+
@full_address = '1 Infinite Loop, Cupertino, CA 95014'
|
9
|
+
@second_address = '300 Brannan St, San Francisco, CA 94107'
|
10
|
+
end
|
11
|
+
|
12
|
+
def assert_url(expected_url)
|
13
|
+
assert_equal expected_url, TestHelper.get_last_url.gsub(/&oauth_[a-z_]+=[a-zA-Z0-9\-. %]+/, '').gsub('%20', '+')
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_geocodio_geocode
|
17
|
+
VCR.use_cassette('geocodio_geocode') do
|
18
|
+
res = Geokit::Geocoders::GeocodioGeocoder.geocode(@full_address)
|
19
|
+
url = "http://api.geocod.io/v1/geocode?q=#{Geokit::Inflector.url_escape(@full_address)}&api_key=723d41115152d224fd74727df34727c444537f7"
|
20
|
+
|
21
|
+
assert_url url
|
22
|
+
|
23
|
+
verify(res)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def verify(location)
|
28
|
+
assert_equal location.city, 'Cupertino'
|
29
|
+
assert_equal location.zip, '95014'
|
30
|
+
assert_equal location.lat, 37.331669
|
31
|
+
assert_equal location.lng, -122.03074
|
32
|
+
end
|
33
|
+
end
|
@@ -33,12 +33,26 @@ class GoogleGeocoderTest < BaseGeocoderTest #:nodoc: all
|
|
33
33
|
url = Geokit::Geocoders::GoogleGeocoder.send(:submit_url, 'address=New+York')
|
34
34
|
Geokit::Geocoders::GoogleGeocoder.client_id = nil
|
35
35
|
Geokit::Geocoders::GoogleGeocoder.cryptographic_key = nil
|
36
|
-
assert_equal '
|
36
|
+
assert_equal 'https://maps.googleapis.com/maps/api/geocode/json?sensor=false&address=New+York&client=clientID&signature=9mevp7SoVsSKzF9nj-vApMYbatg=', url
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_google_api_key
|
40
|
+
Geokit::Geocoders::GoogleGeocoder.api_key = 'someKey'
|
41
|
+
url = Geokit::Geocoders::GoogleGeocoder.send(:submit_url, 'address=New+York')
|
42
|
+
Geokit::Geocoders::GoogleGeocoder.api_key = nil
|
43
|
+
assert_equal 'https://maps.googleapis.com/maps/api/geocode/json?sensor=false&address=New+York&key=someKey', url
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_google_insecure_url
|
47
|
+
Geokit::Geocoders.secure = false
|
48
|
+
url = Geokit::Geocoders::GoogleGeocoder.send(:submit_url, 'address=New+York')
|
49
|
+
Geokit::Geocoders.secure = true
|
50
|
+
assert_equal 'http://maps.google.com/maps/api/geocode/json?sensor=false&address=New+York', url
|
37
51
|
end
|
38
52
|
|
39
53
|
def test_google_full_address
|
40
54
|
VCR.use_cassette('google_full_short') do
|
41
|
-
url = "
|
55
|
+
url = "https://maps.google.com/maps/api/geocode/json?sensor=false&address=#{Geokit::Inflector::url_escape(@address)}"
|
42
56
|
TestHelper.expects(:last_url).with(url)
|
43
57
|
res=Geokit::Geocoders::GoogleGeocoder.geocode(@address)
|
44
58
|
assert_equal "CA", res.state
|
@@ -52,7 +66,7 @@ class GoogleGeocoderTest < BaseGeocoderTest #:nodoc: all
|
|
52
66
|
|
53
67
|
def test_google_full_address_with_geo_loc
|
54
68
|
VCR.use_cassette('google_full') do
|
55
|
-
url = "
|
69
|
+
url = "https://maps.google.com/maps/api/geocode/json?sensor=false&address=#{Geokit::Inflector::url_escape(@full_address_short_zip)}"
|
56
70
|
TestHelper.expects(:last_url).with(url)
|
57
71
|
res=Geokit::Geocoders::GoogleGeocoder.geocode(@google_full_loc)
|
58
72
|
assert_equal "CA", res.state
|
@@ -66,7 +80,7 @@ class GoogleGeocoderTest < BaseGeocoderTest #:nodoc: all
|
|
66
80
|
|
67
81
|
def test_google_full_address_accuracy
|
68
82
|
VCR.use_cassette('google_full') do
|
69
|
-
url = "
|
83
|
+
url = "https://maps.google.com/maps/api/geocode/json?sensor=false&address=#{Geokit::Inflector::url_escape(@full_address_short_zip)}"
|
70
84
|
TestHelper.expects(:last_url).with(url)
|
71
85
|
res=Geokit::Geocoders::GoogleGeocoder.geocode(@google_full_loc)
|
72
86
|
|
@@ -76,7 +90,7 @@ class GoogleGeocoderTest < BaseGeocoderTest #:nodoc: all
|
|
76
90
|
|
77
91
|
def test_google_city
|
78
92
|
VCR.use_cassette('google_city') do
|
79
|
-
url = "
|
93
|
+
url = "https://maps.google.com/maps/api/geocode/json?sensor=false&address=#{Geokit::Inflector::url_escape(@address)}"
|
80
94
|
TestHelper.expects(:last_url).with(url)
|
81
95
|
res=Geokit::Geocoders::GoogleGeocoder.do_geocode(@address)
|
82
96
|
assert_nil res.street_address
|
@@ -91,7 +105,7 @@ class GoogleGeocoderTest < BaseGeocoderTest #:nodoc: all
|
|
91
105
|
|
92
106
|
def test_google_city_accuracy
|
93
107
|
VCR.use_cassette('google_city') do
|
94
|
-
url = "
|
108
|
+
url = "https://maps.google.com/maps/api/geocode/json?sensor=false&address=#{Geokit::Inflector::url_escape(@address)}"
|
95
109
|
TestHelper.expects(:last_url).with(url)
|
96
110
|
res=Geokit::Geocoders::GoogleGeocoder.geocode(@address)
|
97
111
|
assert_equal 4, res.accuracy
|
@@ -100,7 +114,7 @@ class GoogleGeocoderTest < BaseGeocoderTest #:nodoc: all
|
|
100
114
|
|
101
115
|
def test_google_city_with_geo_loc
|
102
116
|
VCR.use_cassette('google_city') do
|
103
|
-
url = "
|
117
|
+
url = "https://maps.google.com/maps/api/geocode/json?sensor=false&address=#{Geokit::Inflector::url_escape(@address)}"
|
104
118
|
TestHelper.expects(:last_url).with(url)
|
105
119
|
res=Geokit::Geocoders::GoogleGeocoder.geocode(@google_city_loc)
|
106
120
|
assert_equal "CA", res.state
|
@@ -115,7 +129,7 @@ class GoogleGeocoderTest < BaseGeocoderTest #:nodoc: all
|
|
115
129
|
|
116
130
|
def test_google_suggested_bounds
|
117
131
|
VCR.use_cassette('google_full') do
|
118
|
-
url = "
|
132
|
+
url = "https://maps.google.com/maps/api/geocode/json?sensor=false&address=#{Geokit::Inflector::url_escape(@full_address_short_zip)}"
|
119
133
|
TestHelper.expects(:last_url).with(url)
|
120
134
|
res = Geokit::Geocoders::GoogleGeocoder.geocode(@google_full_loc)
|
121
135
|
assert_instance_of Geokit::Bounds, res.suggested_bounds
|
@@ -129,21 +143,21 @@ class GoogleGeocoderTest < BaseGeocoderTest #:nodoc: all
|
|
129
143
|
Geokit::LatLng.new(33.7036917, -118.6681759),
|
130
144
|
Geokit::LatLng.new(34.3373061, -118.1552891)
|
131
145
|
)
|
132
|
-
url = "
|
146
|
+
url = "https://maps.google.com/maps/api/geocode/json?sensor=false&address=Winnetka&bounds=33.7036917%2C-118.6681759%7C34.3373061%2C-118.1552891"
|
133
147
|
Geokit::Geocoders::GoogleGeocoder.expects(:call_geocoder_service).with(url)
|
134
148
|
Geokit::Geocoders::GoogleGeocoder.geocode('Winnetka', :bias => bounds)
|
135
149
|
end
|
136
150
|
|
137
151
|
def test_service_unavailable
|
138
152
|
response = MockFailure.new
|
139
|
-
url = "
|
153
|
+
url = "https://maps.google.com/maps/api/geocode/json?sensor=false&address=#{Geokit::Inflector::url_escape(@address)}"
|
140
154
|
Geokit::Geocoders::GoogleGeocoder.expects(:call_geocoder_service).with(url).returns(response)
|
141
155
|
assert !Geokit::Geocoders::GoogleGeocoder.geocode(@google_city_loc).success
|
142
156
|
end
|
143
157
|
|
144
158
|
def test_multiple_results
|
145
159
|
VCR.use_cassette('google_multi') do
|
146
|
-
url = "
|
160
|
+
url = "https://maps.google.com/maps/api/geocode/json?sensor=false&address=#{Geokit::Inflector.url_escape('via Sandro Pertini 8, Ossona, MI')}"
|
147
161
|
TestHelper.expects(:last_url).with(url)
|
148
162
|
res=Geokit::Geocoders::GoogleGeocoder.geocode('via Sandro Pertini 8, Ossona, MI')
|
149
163
|
assert_equal 5, res.all.size
|
@@ -171,7 +185,7 @@ class GoogleGeocoderTest < BaseGeocoderTest #:nodoc: all
|
|
171
185
|
VCR.use_cassette('google_reverse_madrid') do
|
172
186
|
madrid = Geokit::GeoLoc.new
|
173
187
|
madrid.lat, madrid.lng = "40.4167413", "-3.7032498"
|
174
|
-
url = "
|
188
|
+
url = "https://maps.google.com/maps/api/geocode/json?sensor=false&latlng=#{Geokit::Inflector::url_escape(madrid.ll)}"
|
175
189
|
TestHelper.expects(:last_url).with(url)
|
176
190
|
res=Geokit::Geocoders::GoogleGeocoder.do_reverse_geocode(madrid.ll)
|
177
191
|
|
@@ -191,7 +205,7 @@ class GoogleGeocoderTest < BaseGeocoderTest #:nodoc: all
|
|
191
205
|
|
192
206
|
def test_reverse_geocode_language
|
193
207
|
VCR.use_cassette('google_reverse_madrid_es') do
|
194
|
-
url = "
|
208
|
+
url = "https://maps.google.com/maps/api/geocode/json?sensor=false&latlng=40.416%2C-3.703&language=es"
|
195
209
|
TestHelper.expects(:last_url).with(url)
|
196
210
|
language_result = Geokit::Geocoders::GoogleGeocoder.reverse_geocode('40.416,-3.703', :language => 'es')
|
197
211
|
|
@@ -202,7 +216,7 @@ class GoogleGeocoderTest < BaseGeocoderTest #:nodoc: all
|
|
202
216
|
|
203
217
|
def test_country_code_biasing
|
204
218
|
VCR.use_cassette('google_country_code_biased_result') do
|
205
|
-
url = "
|
219
|
+
url = "https://maps.google.com/maps/api/geocode/json?sensor=false&address=Syracuse®ion=it"
|
206
220
|
TestHelper.expects(:last_url).with(url)
|
207
221
|
biased_result = Geokit::Geocoders::GoogleGeocoder.geocode('Syracuse', :bias => 'it')
|
208
222
|
|
@@ -213,7 +227,7 @@ class GoogleGeocoderTest < BaseGeocoderTest #:nodoc: all
|
|
213
227
|
|
214
228
|
def test_language_response
|
215
229
|
VCR.use_cassette('google_language_response_fr') do
|
216
|
-
url = "
|
230
|
+
url = "https://maps.google.com/maps/api/geocode/json?sensor=false&address=Hanoi&language=FR"
|
217
231
|
TestHelper.expects(:last_url).with(url)
|
218
232
|
language_result = Geokit::Geocoders::GoogleGeocoder.geocode('Hanoi', :language => 'FR')
|
219
233
|
|
@@ -225,7 +239,7 @@ class GoogleGeocoderTest < BaseGeocoderTest #:nodoc: all
|
|
225
239
|
def test_too_many_queries
|
226
240
|
response = MockSuccess.new
|
227
241
|
response.expects(:body).returns %q/{"status": "OVER_QUERY_LIMIT"}/
|
228
|
-
url = "
|
242
|
+
url = "https://maps.google.com/maps/api/geocode/json?sensor=false&address=#{Geokit::Inflector.url_escape(@address)}"
|
229
243
|
Geokit::Geocoders::GoogleGeocoder.expects(:call_geocoder_service).with(url).returns(response)
|
230
244
|
assert_raise Geokit::Geocoders::TooManyQueriesError do
|
231
245
|
res=Geokit::Geocoders::GoogleGeocoder.geocode(@address)
|
@@ -235,7 +249,7 @@ class GoogleGeocoderTest < BaseGeocoderTest #:nodoc: all
|
|
235
249
|
def test_invalid_request
|
236
250
|
response = MockSuccess.new
|
237
251
|
response.expects(:body).returns %q/{"results" : [], "status" : "INVALID_REQUEST"}/
|
238
|
-
url = "
|
252
|
+
url = "https://maps.google.com/maps/api/geocode/json?sensor=false&address=#{Geokit::Inflector.url_escape("3961 V\u00EDa Marisol")}"
|
239
253
|
Geokit::Geocoders::GoogleGeocoder.expects(:call_geocoder_service).with(url).returns(response)
|
240
254
|
assert_raise Geokit::Geocoders::GeocodeError do
|
241
255
|
Geokit::Geocoders::GoogleGeocoder.geocode("3961 V\u00EDa Marisol")
|