geokit 1.8.4 → 1.8.5
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -2,48 +2,42 @@
|
|
2
2
|
http_interactions:
|
3
3
|
- request:
|
4
4
|
method: get
|
5
|
-
uri:
|
5
|
+
uri: https://maps.google.com/maps/api/geocode/json?language=es&latlng=40.416,-3.703&sensor=false
|
6
6
|
body:
|
7
7
|
encoding: US-ASCII
|
8
8
|
string: ''
|
9
9
|
headers:
|
10
|
+
Accept-Encoding:
|
11
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
10
12
|
Accept:
|
11
|
-
-
|
13
|
+
- '*/*'
|
12
14
|
User-Agent:
|
13
15
|
- Ruby
|
14
16
|
response:
|
15
17
|
status:
|
16
18
|
code: 200
|
17
|
-
message:
|
18
|
-
T0s=
|
19
|
+
message: OK
|
19
20
|
headers:
|
20
|
-
|
21
|
-
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
-
|
34
|
-
|
35
|
-
|
36
|
-
-
|
37
|
-
|
38
|
-
|
39
|
-
-
|
40
|
-
MTsgbW9kZT1ibG9jaw==
|
41
|
-
!binary "WC1GcmFtZS1PcHRpb25z":
|
42
|
-
- !binary |-
|
43
|
-
U0FNRU9SSUdJTg==
|
44
|
-
!binary "VHJhbnNmZXItRW5jb2Rpbmc=":
|
45
|
-
- !binary |-
|
46
|
-
Y2h1bmtlZA==
|
21
|
+
Content-Type:
|
22
|
+
- application/json; charset=UTF-8
|
23
|
+
Date:
|
24
|
+
- Sun, 26 Jan 2014 05:46:39 GMT
|
25
|
+
Expires:
|
26
|
+
- Mon, 27 Jan 2014 05:46:39 GMT
|
27
|
+
Cache-Control:
|
28
|
+
- public, max-age=86400
|
29
|
+
Access-Control-Allow-Origin:
|
30
|
+
- '*'
|
31
|
+
Server:
|
32
|
+
- mafe
|
33
|
+
X-Xss-Protection:
|
34
|
+
- 1; mode=block
|
35
|
+
X-Frame-Options:
|
36
|
+
- SAMEORIGIN
|
37
|
+
Alternate-Protocol:
|
38
|
+
- 443:quic
|
39
|
+
Transfer-Encoding:
|
40
|
+
- chunked
|
47
41
|
body:
|
48
42
|
encoding: ASCII-8BIT
|
49
43
|
string: !binary |-
|
@@ -459,5 +453,5 @@ http_interactions:
|
|
459
453
|
dHlwZXMiIDogWyAiY291bnRyeSIsICJwb2xpdGljYWwiIF0KICAgICAgfQog
|
460
454
|
ICBdLAogICAic3RhdHVzIiA6ICJPSyIKfQo=
|
461
455
|
http_version:
|
462
|
-
recorded_at:
|
456
|
+
recorded_at: Sun, 26 Jan 2014 05:46:40 GMT
|
463
457
|
recorded_with: VCR 2.8.0
|
@@ -0,0 +1,53 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: https://www.mapquestapi.com/geocoding/v1/address?key=Fmjtd%7Cluur2d0125,2s=o5-9a8lhz&location=100%20Spear%20St%20Apt.%205,%20San%20Francisco,%20CA,%2094105,%20US
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
Accept-Encoding:
|
11
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
12
|
+
Accept:
|
13
|
+
- "*/*"
|
14
|
+
User-Agent:
|
15
|
+
- Ruby
|
16
|
+
response:
|
17
|
+
status:
|
18
|
+
code: 200
|
19
|
+
message: OK
|
20
|
+
headers:
|
21
|
+
Server:
|
22
|
+
- Apache-Coyote/1.1
|
23
|
+
Set-Cookie:
|
24
|
+
- JSESSIONID=A737A4684852AE01983F5AA9FA4321C4; Path=/; HttpOnly
|
25
|
+
Expires:
|
26
|
+
- Mon, 20 Dec 1998 01:00:00 GMT
|
27
|
+
Last-Modified:
|
28
|
+
- Thu, 29 May 2014 13:38:05 GMT
|
29
|
+
Cache-Control:
|
30
|
+
- no-cache, must-revalidate
|
31
|
+
Pragma:
|
32
|
+
- no-cache
|
33
|
+
Access-Control-Allow-Origin:
|
34
|
+
- "*"
|
35
|
+
Access-Control-Allow-Methods:
|
36
|
+
- OPTIONS,GET,POST
|
37
|
+
Content-Type:
|
38
|
+
- application/json;charset=UTF-8
|
39
|
+
Transfer-Encoding:
|
40
|
+
- chunked
|
41
|
+
Date:
|
42
|
+
- Thu, 29 May 2014 13:38:04 GMT
|
43
|
+
body:
|
44
|
+
encoding: UTF-8
|
45
|
+
string: "{\"info\":{\"statuscode\":0,\"copyright\":{\"text\":\"\\u00A9 2014
|
46
|
+
MapQuest, Inc.\",\"imageUrl\":\"https://api.mqcdn.com/res/mqlogo.gif\",\"imageAltText\":\"\\u00A9
|
47
|
+
2014 MapQuest, Inc.\"},\"messages\":[]},\"options\":{\"maxResults\":-1,\"thumbMaps\":true,\"ignoreLatLngInput\":false},\"results\":[{\"providedLocation\":{\"location\":\"100
|
48
|
+
Spear St Apt. 5, San Francisco, CA, 94105, US\"},\"locations\":[{\"street\":\"100
|
49
|
+
Spear St, APT 5\",\"adminArea5\":\"San Francisco\",\"adminArea5Type\":\"City\",\"adminArea4\":\"San
|
50
|
+
Francisco\",\"adminArea4Type\":\"County\",\"adminArea3\":\"CA\",\"adminArea3Type\":\"State\",\"adminArea1\":\"US\",\"adminArea1Type\":\"Country\",\"postalCode\":\"94105-1500\",\"geocodeQualityCode\":\"P1AAA\",\"geocodeQuality\":\"POINT\",\"dragPoint\":false,\"sideOfStreet\":\"R\",\"linkId\":\"68400005996374\",\"unknownInput\":\"\",\"type\":\"s\",\"latLng\":{\"lat\":37.792305,\"lng\":-122.393776},\"displayLatLng\":{\"lat\":37.79215,\"lng\":-122.394},\"mapUrl\":\"https://www.mapquestapi.com/staticmap/v4/getmap?key=Fmjtd|luur2d0125,2s=o5-9a8lhz&type=map&size=225,160&pois=purple-1,37.792305,-122.393776,0,0,|¢er=37.792305,-122.393776&zoom=15&rand=-150371976\"}]}]}"
|
51
|
+
http_version:
|
52
|
+
recorded_at: Thu, 29 May 2014 13:38:05 GMT
|
53
|
+
recorded_with: VCR 2.8.0
|
@@ -0,0 +1,52 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: https://www.mapquestapi.com/geocoding/v1/reverse?key=Fmjtd%7Cluur2d0125,2s=o5-9a8lhz&location=40.4167413,-3.7032498
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
Accept-Encoding:
|
11
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
12
|
+
Accept:
|
13
|
+
- "*/*"
|
14
|
+
User-Agent:
|
15
|
+
- Ruby
|
16
|
+
response:
|
17
|
+
status:
|
18
|
+
code: 200
|
19
|
+
message: OK
|
20
|
+
headers:
|
21
|
+
Server:
|
22
|
+
- Apache-Coyote/1.1
|
23
|
+
Set-Cookie:
|
24
|
+
- JSESSIONID=3BC67F1FAE87C7DA0C84F86919DF3E1E; Path=/; HttpOnly
|
25
|
+
Expires:
|
26
|
+
- Mon, 20 Dec 1998 01:00:00 GMT
|
27
|
+
Last-Modified:
|
28
|
+
- Thu, 29 May 2014 13:38:06 GMT
|
29
|
+
Cache-Control:
|
30
|
+
- no-cache, must-revalidate
|
31
|
+
Pragma:
|
32
|
+
- no-cache
|
33
|
+
Access-Control-Allow-Origin:
|
34
|
+
- "*"
|
35
|
+
Access-Control-Allow-Methods:
|
36
|
+
- OPTIONS,GET,POST
|
37
|
+
Content-Type:
|
38
|
+
- application/json;charset=UTF-8
|
39
|
+
Transfer-Encoding:
|
40
|
+
- chunked
|
41
|
+
Date:
|
42
|
+
- Thu, 29 May 2014 13:38:06 GMT
|
43
|
+
body:
|
44
|
+
encoding: UTF-8
|
45
|
+
string: "{\"info\":{\"statuscode\":0,\"copyright\":{\"text\":\"\\u00A9 2014
|
46
|
+
MapQuest, Inc.\",\"imageUrl\":\"https://api.mqcdn.com/res/mqlogo.gif\",\"imageAltText\":\"\\u00A9
|
47
|
+
2014 MapQuest, Inc.\"},\"messages\":[]},\"options\":{\"maxResults\":1,\"thumbMaps\":true,\"ignoreLatLngInput\":false},\"results\":[{\"providedLocation\":{\"latLng\":{\"lat\":40.4167413,\"lng\":-3.7032498}},\"locations\":[{\"street\":\"\",\"adminArea5\":\"Madrid\",\"adminArea5Type\":\"City\",\"adminArea4\":\"\\u00C1rea
|
48
|
+
metropolitana de Madrid y Corredor del Henares\",\"adminArea4Type\":\"County\",\"adminArea3\":\"Comunidad
|
49
|
+
de Madrid\",\"adminArea3Type\":\"State\",\"adminArea1\":\"ES\",\"adminArea1Type\":\"Country\",\"postalCode\":\"28014\",\"geocodeQualityCode\":\"Z1XAA\",\"geocodeQuality\":\"ZIP\",\"dragPoint\":false,\"sideOfStreet\":\"N\",\"linkId\":\"0\",\"unknownInput\":\"\",\"type\":\"s\",\"latLng\":{\"lat\":40.41686,\"lng\":-3.70348},\"displayLatLng\":{\"lat\":40.41686,\"lng\":-3.70348},\"mapUrl\":\"https://www.mapquestapi.com/staticmap/v4/getmap?key=Fmjtd|luur2d0125,2s=o5-9a8lhz&type=map&size=225,160&pois=purple-1,40.41685975,-3.70348049982096,0,0,|¢er=40.41685975,-3.70348049982096&zoom=15&rand=-639817840\"}]}]}"
|
50
|
+
http_version:
|
51
|
+
recorded_at: Thu, 29 May 2014 13:38:06 GMT
|
52
|
+
recorded_with: VCR 2.8.0
|
@@ -0,0 +1,45 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: http://stat.ripe.net/data/geoloc/data.json?resource=45.45.45.45
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
Accept-Encoding:
|
11
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
12
|
+
Accept:
|
13
|
+
- "*/*"
|
14
|
+
User-Agent:
|
15
|
+
- Ruby
|
16
|
+
response:
|
17
|
+
status:
|
18
|
+
code: 200
|
19
|
+
message: OK
|
20
|
+
headers:
|
21
|
+
Vary:
|
22
|
+
- Cookie, Accept-Encoding
|
23
|
+
Content-Length:
|
24
|
+
- '274'
|
25
|
+
Content-Type:
|
26
|
+
- application/json; charset=utf-8
|
27
|
+
Set-Cookie:
|
28
|
+
- stat-session=31cebc7bc2ff5c195bcad049a37ab4b2; expires=Wed, 11-Jun-2014 10:59:59
|
29
|
+
GMT; httponly; Max-Age=1209600; Path=/
|
30
|
+
Date:
|
31
|
+
- Wed, 28 May 2014 10:59:59 GMT
|
32
|
+
Server:
|
33
|
+
- lighttpd/1.4.32
|
34
|
+
body:
|
35
|
+
encoding: UTF-8
|
36
|
+
string: "{\n \"cached\": true, \n \"data\": {\n \"locations\":
|
37
|
+
[], \n \"query_time\": \"2014-05-01T00:00:00\", \n \"resource\":
|
38
|
+
\"45.45.45.45\", \n \"unknown_percentage\": 100.0\n }, \n \"data_call_status\":
|
39
|
+
\"supported\", \n \"messages\": [], \n \"process_time\": 7, \n \"query_id\":
|
40
|
+
\"35d010ee-e657-11e3-adde-782bcb346712\", \n \"see_also\": [], \n \"server_id\":
|
41
|
+
\"stat-app2\", \n \"status\": \"ok\", \n \"status_code\": 200, \n \"time\":
|
42
|
+
\"2014-05-28T10:59:59.069345\", \n \"version\": \"2.0\"\n}"
|
43
|
+
http_version:
|
44
|
+
recorded_at: Wed, 28 May 2014 10:59:59 GMT
|
45
|
+
recorded_with: VCR 2.8.0
|
@@ -2,7 +2,7 @@
|
|
2
2
|
http_interactions:
|
3
3
|
- request:
|
4
4
|
method: get
|
5
|
-
uri:
|
5
|
+
uri: https://yboss.yahooapis.com/geo/placefinder?flags=J&oauth_consumer_key=dj0yJmk9cXByQVN2WHZmTVhDJmQ9WVdrOVZscG1WVWhOTldrbWNHbzlNakF6TlRJME16UTJNZy0tJnM9Y29uc3VtZXJzZWNyZXQmeD0zNg--&oauth_nonce=731410e6df&oauth_signature=%2Bde/2eYXvMPhoRu5MUdjhPct3xY=&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1384355278&oauth_version=1.0&q=San%20Francisco,%20CA
|
6
6
|
body:
|
7
7
|
encoding: US-ASCII
|
8
8
|
string: ''
|
@@ -2,7 +2,7 @@
|
|
2
2
|
http_interactions:
|
3
3
|
- request:
|
4
4
|
method: get
|
5
|
-
uri:
|
5
|
+
uri: https://yboss.yahooapis.com/geo/placefinder?flags=J&oauth_consumer_key=dj0yJmk9cXByQVN2WHZmTVhDJmQ9WVdrOVZscG1WVWhOTldrbWNHbzlNakF6TlRJME16UTJNZy0tJnM9Y29uc3VtZXJzZWNyZXQmeD0zNg--&oauth_nonce=7a0ce94e38&oauth_signature=aTamhmDusxM4xYZXWocDEb5YmyE=&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1384355278&oauth_version=1.0&q=100%20Spear%20St,%20San%20Francisco,%20CA,%2094105-1522,%20US
|
6
6
|
body:
|
7
7
|
encoding: US-ASCII
|
8
8
|
string: ''
|
@@ -2,7 +2,7 @@
|
|
2
2
|
http_interactions:
|
3
3
|
- request:
|
4
4
|
method: get
|
5
|
-
uri:
|
5
|
+
uri: https://yboss.yahooapis.com/geo/placefinder?flags=J&oauth_consumer_key=dj0yJmk9cXByQVN2WHZmTVhDJmQ9WVdrOVZscG1WVWhOTldrbWNHbzlNakF6TlRJME16UTJNZy0tJnM9Y29uc3VtZXJzZWNyZXQmeD0zNg--&oauth_nonce=2c5ad2f846&oauth_signature=h2eR3b0GSWsgqU2nJhd1jPP8ihI=&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1384355895&oauth_version=1.0&q=ZZ,%20ZZ,%20ZZ
|
6
6
|
body:
|
7
7
|
encoding: US-ASCII
|
8
8
|
string: ''
|
data/lib/geokit/geocoders.rb
CHANGED
@@ -40,6 +40,8 @@ module Geokit
|
|
40
40
|
@@logger.level=Logger::INFO
|
41
41
|
@@domain = nil
|
42
42
|
@@net_adapter = Geokit::NetAdapter::NetHttp
|
43
|
+
@@secure = true
|
44
|
+
@@ssl_verify_mode = OpenSSL::SSL::VERIFY_PEER
|
43
45
|
|
44
46
|
def self.__define_accessors
|
45
47
|
class_variables.each do |v|
|
@@ -87,8 +89,9 @@ module Geokit
|
|
87
89
|
do_geocode(address, *args) || GeoLoc.new
|
88
90
|
rescue TooManyQueriesError, GeocodeError
|
89
91
|
raise
|
90
|
-
rescue
|
92
|
+
rescue => e
|
91
93
|
logger.error "Caught an error during #{provider_name} geocoding call: #{$!}"
|
94
|
+
logger.error e.backtrace.join("\n")
|
92
95
|
GeoLoc.new
|
93
96
|
end
|
94
97
|
# Main method which calls the do_reverse_geocode template method which subclasses
|
@@ -121,6 +124,10 @@ module Geokit
|
|
121
124
|
end
|
122
125
|
end
|
123
126
|
|
127
|
+
def self.inherited(base)
|
128
|
+
base.config :secure
|
129
|
+
end
|
130
|
+
|
124
131
|
def self.new_loc
|
125
132
|
loc = GeoLoc.new
|
126
133
|
loc.provider = Geokit::Inflector.underscore(provider_name)
|
@@ -142,6 +149,14 @@ module Geokit
|
|
142
149
|
GeoLoc.new
|
143
150
|
end
|
144
151
|
|
152
|
+
def self.use_https?
|
153
|
+
self.secure && Geokit::Geocoders.secure
|
154
|
+
end
|
155
|
+
|
156
|
+
def self.protocol
|
157
|
+
use_https? ? 'https' : 'http'
|
158
|
+
end
|
159
|
+
|
145
160
|
# Wraps the geocoder call around a proxy if necessary.
|
146
161
|
def self.do_get(url)
|
147
162
|
net_adapter.do_get(url)
|
@@ -4,6 +4,7 @@ module Geokit
|
|
4
4
|
# contain a Bing Maps API key. Conforms to the interface set by the Geocoder class.
|
5
5
|
class BingGeocoder < Geocoder
|
6
6
|
config :key, :options
|
7
|
+
self.secure = true
|
7
8
|
|
8
9
|
private
|
9
10
|
|
@@ -20,7 +21,7 @@ module Geokit
|
|
20
21
|
culture = options && options[:culture]
|
21
22
|
culture_string = culture ? "&c=#{culture}" : ''
|
22
23
|
address_str = address.is_a?(GeoLoc) ? address.to_geocodeable_s : address
|
23
|
-
"
|
24
|
+
"#{protocol}://dev.virtualearth.net/REST/v1/Locations/#{URI.escape(address_str)}?key=#{key}#{culture_string}&o=xml"
|
24
25
|
end
|
25
26
|
|
26
27
|
def self.parse_xml(xml)
|
@@ -61,28 +62,31 @@ module Geokit
|
|
61
62
|
set_mappings(loc, xml, XML_MAPPINGS)
|
62
63
|
end
|
63
64
|
|
65
|
+
ACCURACY_MAP = {
|
66
|
+
'High' => 8,
|
67
|
+
'Medium' => 5,
|
68
|
+
'Low' => 2
|
69
|
+
}
|
70
|
+
|
71
|
+
PRECISION_MAP = {
|
72
|
+
'Sovereign' => 'country',
|
73
|
+
'CountryRegion' => 'country',
|
74
|
+
'AdminDivision1' => 'state',
|
75
|
+
'AdminDivision2' => 'state',
|
76
|
+
'PopulatedPlace' => 'city',
|
77
|
+
'Postcode1' => 'zip',
|
78
|
+
'Postcode2' => 'zip',
|
79
|
+
'RoadBlock' => 'street',
|
80
|
+
'Address' => 'address'
|
81
|
+
}
|
82
|
+
|
64
83
|
def self.set_precision(loc, xml)
|
65
84
|
if xml.elements['.//Confidence']
|
66
|
-
loc.accuracy
|
67
|
-
when 'High' then 8
|
68
|
-
when 'Medium' then 5
|
69
|
-
when 'Low' then 2
|
70
|
-
else 0
|
71
|
-
end
|
85
|
+
loc.accuracy = ACCURACY_MAP[xml.elements['.//Confidence'].text] || 0
|
72
86
|
end
|
73
87
|
|
74
88
|
if xml.elements['.//EntityType']
|
75
|
-
loc.precision
|
76
|
-
when 'Sovereign' then 'country'
|
77
|
-
when 'AdminDivision1' then 'state'
|
78
|
-
when 'AdminDivision2' then 'state'
|
79
|
-
when 'PopulatedPlace' then 'city'
|
80
|
-
when 'Postcode1' then 'zip'
|
81
|
-
when 'Postcode2' then 'zip'
|
82
|
-
when 'RoadBlock' then 'street'
|
83
|
-
when 'Address' then 'address'
|
84
|
-
else 'unkown'
|
85
|
-
end
|
89
|
+
loc.precision = PRECISION_MAP[xml.elements['.//EntityType'].text] || 'unknown'
|
86
90
|
end
|
87
91
|
end
|
88
92
|
|
data/lib/geokit/geocoders/fcc.rb
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
module Geokit
|
2
2
|
module Geocoders
|
3
3
|
class FCCGeocoder < Geocoder
|
4
|
+
self.secure = true
|
4
5
|
|
5
6
|
private
|
6
7
|
# Template method which does the reverse-geocode lookup.
|
7
8
|
def self.do_reverse_geocode(latlng)
|
8
9
|
latlng=LatLng.normalize(latlng)
|
9
|
-
url = "
|
10
|
+
url = "#{protocol}://data.fcc.gov/api/block/find?format=json&latitude=#{Geokit::Inflector::url_escape(latlng.lat.to_s)}&longitude=#{Geokit::Inflector::url_escape(latlng.lng.to_s)}"
|
10
11
|
process :json, url
|
11
12
|
end
|
12
13
|
|
@@ -0,0 +1,59 @@
|
|
1
|
+
module Geokit
|
2
|
+
module Geocoders
|
3
|
+
class GeocodioGeocoder < Geocoder
|
4
|
+
config :key
|
5
|
+
|
6
|
+
private
|
7
|
+
|
8
|
+
def self.do_geocode(address)
|
9
|
+
process :json, submit_url(address)
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.submit_url(address)
|
13
|
+
params = [
|
14
|
+
"q=#{Geokit::Inflector::url_escape(address)}",
|
15
|
+
"api_key=#{key}"
|
16
|
+
].join('&')
|
17
|
+
|
18
|
+
['http://api.geocod.io/v1/geocode', params].join('?')
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.parse_json(json)
|
22
|
+
loc = nil
|
23
|
+
|
24
|
+
json['results'].each do |address|
|
25
|
+
if loc.nil?
|
26
|
+
loc = create_new_loc(address)
|
27
|
+
else
|
28
|
+
loc.all.push(create_new_loc(address))
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
loc
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.create_new_loc(json)
|
36
|
+
loc = new_loc
|
37
|
+
set_address_components(json, loc)
|
38
|
+
set_coordinates(json, loc)
|
39
|
+
loc
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.set_address_components(json, loc)
|
43
|
+
loc.street_address = json['address_components']['street']
|
44
|
+
loc.street_number = json['address_components']['number']
|
45
|
+
loc.sub_premise = json['address_components']['suffix']
|
46
|
+
loc.street_name = json['address_components']['street']
|
47
|
+
loc.city = json['address_components']['city']
|
48
|
+
loc.state = json['address_components']['state']
|
49
|
+
loc.zip = json['address_components']['zip']
|
50
|
+
loc.full_address = json['formatted_address']
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.set_coordinates(json, loc)
|
54
|
+
loc.lat = json['location']['lat']
|
55
|
+
loc.lng = json['location']['lng']
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|