geokit 1.8.5 → 1.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.travis.yml +0 -1
- data/CHANGELOG.md +7 -0
- data/README.markdown +31 -14
- data/fixtures/vcr_cassettes/geonames_geocode.yml +1 -1
- data/fixtures/vcr_cassettes/geonames_geocode_premium.yml +42 -0
- data/fixtures/vcr_cassettes/google_country_code_biased_result_orly.yml +160 -0
- data/fixtures/vcr_cassettes/google_country_code_biased_result_toledo.yml +111 -0
- data/fixtures/vcr_cassettes/google_result_toledo_default_bias.yml +275 -0
- data/fixtures/vcr_cassettes/google_sublocality.yml +126 -0
- data/fixtures/vcr_cassettes/mapbox_forward_geocode.yml +59 -0
- data/fixtures/vcr_cassettes/mapbox_reverse_geocode.yml +63 -0
- data/fixtures/vcr_cassettes/opencage_city.yml +51 -0
- data/fixtures/vcr_cassettes/opencage_full.yml +65 -0
- data/fixtures/vcr_cassettes/opencage_language_response_es.yml +66 -0
- data/fixtures/vcr_cassettes/opencage_reverse_madrid.yml +51 -0
- data/fixtures/vcr_cassettes/opencage_reverse_prilep.yml +53 -0
- data/geokit.gemspec +5 -3
- data/lib/geokit/bounds.rb +40 -31
- data/lib/geokit/core_ext.rb +1 -1
- data/lib/geokit/geo_loc.rb +63 -41
- data/lib/geokit/geocoders.rb +13 -13
- data/lib/geokit/geocoders/bing.rb +9 -9
- data/lib/geokit/geocoders/ca_geocoder.rb +29 -29
- data/lib/geokit/geocoders/fcc.rb +4 -4
- data/lib/geokit/geocoders/free_geo_ip.rb +6 -7
- data/lib/geokit/geocoders/geo_plugin.rb +5 -6
- data/lib/geokit/geocoders/geocodio.rb +2 -2
- data/lib/geokit/geocoders/geonames.rb +18 -12
- data/lib/geokit/geocoders/google.rb +31 -30
- data/lib/geokit/geocoders/ip.rb +3 -4
- data/lib/geokit/geocoders/mapbox.rb +94 -0
- data/lib/geokit/geocoders/mapquest.rb +5 -5
- data/lib/geokit/geocoders/opencage.rb +93 -0
- data/lib/geokit/geocoders/openstreetmap.rb +9 -6
- data/lib/geokit/geocoders/ripe.rb +3 -3
- data/lib/geokit/geocoders/us_geocoder.rb +10 -9
- data/lib/geokit/geocoders/yahoo.rb +33 -34
- data/lib/geokit/geocoders/yandex.rb +17 -17
- data/lib/geokit/inflectors.rb +4 -10
- data/lib/geokit/lat_lng.rb +50 -26
- data/lib/geokit/mappable.rb +83 -83
- data/lib/geokit/multi_geocoder.rb +25 -20
- data/lib/geokit/net_adapter/net_http.rb +7 -4
- data/lib/geokit/polygon.rb +36 -4
- data/lib/geokit/version.rb +1 -1
- data/test/helper.rb +15 -13
- data/test/test_base_geocoder.rb +6 -7
- data/test/test_bing_geocoder.rb +20 -21
- data/test/test_bounds.rb +26 -28
- data/test/test_ca_geocoder.rb +9 -10
- data/test/test_fcc_geocoder.rb +1 -1
- data/test/test_free_geo_ip_geocoder.rb +1 -1
- data/test/test_geo_plugin_geocoder.rb +9 -9
- data/test/test_geoloc.rb +7 -6
- data/test/test_geonames_geocoder.rb +28 -6
- data/test/test_google_geocoder.rb +210 -176
- data/test/test_inflector.rb +0 -1
- data/test/test_ipgeocoder.rb +17 -18
- data/test/test_latlng.rb +105 -85
- data/test/test_map_quest.rb +18 -21
- data/test/test_mapbox_geocoder.rb +31 -0
- data/test/test_mappable.rb +46 -0
- data/test/test_maxmind_geocoder.rb +1 -3
- data/test/test_multi_geocoder.rb +8 -9
- data/test/test_multi_ip_geocoder.rb +3 -5
- data/test/test_net_adapter.rb +4 -4
- data/test/test_opencage_geocoder.rb +108 -0
- data/test/test_openstreetmap_geocoder.rb +62 -44
- data/test/{test_polygon_contains.rb → test_polygon.rb} +30 -20
- data/test/test_ripe_geocoder.rb +2 -0
- data/test/test_us_geocoder.rb +7 -8
- data/test/test_yahoo_geocoder.rb +20 -21
- data/test/test_yandex_geocoder.rb +34 -35
- metadata +79 -56
- data/fixtures/vcr_cassettes/google_country_code_biased_result.yml +0 -401
@@ -0,0 +1,63 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: https://api.tiles.mapbox.com/v4/geocode/mapbox.places-v1/-77.032458,38.913175.json?access_token=
|
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
|
+
Content-Type:
|
22
|
+
- application/vnd.geo+json; charset=utf-8
|
23
|
+
Content-Length:
|
24
|
+
- '1902'
|
25
|
+
Connection:
|
26
|
+
- keep-alive
|
27
|
+
Access-Control-Allow-Methods:
|
28
|
+
- GET
|
29
|
+
Access-Control-Allow-Origin:
|
30
|
+
- '*'
|
31
|
+
Cache-Control:
|
32
|
+
- max-age=3600
|
33
|
+
Date:
|
34
|
+
- Thu, 21 Aug 2014 05:46:02 GMT
|
35
|
+
Etag:
|
36
|
+
- '"90af4b2c9697b67786ad9039a4174ff1"'
|
37
|
+
Last-Modified:
|
38
|
+
- Thu, 21 Aug 2014 05:46:02 GMT
|
39
|
+
Server:
|
40
|
+
- nginx
|
41
|
+
X-Powered-By:
|
42
|
+
- Express
|
43
|
+
X-Cache:
|
44
|
+
- Miss from cloudfront
|
45
|
+
Via:
|
46
|
+
- 1.1 565d425ab1cf4d8d6fb4c465f8b73889.cloudfront.net (CloudFront)
|
47
|
+
X-Amz-Cf-Id:
|
48
|
+
- 8KyW9WZU-vDaHl2_CwBdm0F-eiOtOKIUOnRSgiE3MBU4vnHikk_rUA==
|
49
|
+
body:
|
50
|
+
encoding: UTF-8
|
51
|
+
string: '{"type":"FeatureCollection","query":[-77.032458,38.913175],"features":[{"id":"city.20001","type":"Feature","text":"Washington","place_name":"Washington,
|
52
|
+
20009, District of Columbia, United States","relevance":1,"center":[-76.992695,38.899393],"geometry":{"type":"Point","coordinates":[-76.992695,38.899393]},"bbox":[-77.11976790632382,38.80310600134152,-76.90938401684849,38.99555498159024],"properties":{"title":"Washington"},"context":[{"id":"postcode-us.1308149819","text":"20009"},{"id":"province.1190806886","text":"District
|
53
|
+
of Columbia"},{"id":"country.4150104525","text":"United States"}]},{"id":"postcode-us.1308149819","type":"Feature","text":"20009","place_name":"20009,
|
54
|
+
District of Columbia, United States","relevance":1,"center":[-77.038291,38.920148],"geometry":{"type":"Point","coordinates":[-77.038291,38.920148]},"bbox":[-77.050216,38.911122999999996,-77.02703300000002,38.92974399999999],"properties":{"title":"20009"},"context":[{"id":"province.1190806886","text":"District
|
55
|
+
of Columbia"},{"id":"country.4150104525","text":"United States"}]},{"id":"province.1190806886","type":"Feature","text":"District
|
56
|
+
of Columbia","place_name":"District of Columbia, United States","relevance":1,"center":[-76.987826,38.893698],"geometry":{"type":"Point","coordinates":[-76.987826,38.893698]},"bbox":[-77.119759,38.791644999999995,-76.90939299999998,38.99554799999999],"properties":{"title":"District
|
57
|
+
of Columbia"},"context":[{"id":"country.4150104525","text":"United States"}]},{"id":"country.4150104525","type":"Feature","text":"United
|
58
|
+
States","place_name":"United States","relevance":1,"center":[-99.041476,37.940855],"geometry":{"type":"Point","coordinates":[-99.041476,37.940855]},"bbox":[-179.23108600000003,18.865459999999985,179.85968099999997,71.441059],"properties":{"title":"United
|
59
|
+
States"}}],"attribution":"<a href=''https://www.mapbox.com/about/maps/'' target=''_blank''>©
|
60
|
+
Mapbox</a>"}'
|
61
|
+
http_version:
|
62
|
+
recorded_at: Thu, 21 Aug 2014 05:46:00 GMT
|
63
|
+
recorded_with: VCR 2.9.2
|
@@ -0,0 +1,51 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: https://api.opencagedata.com/geocode/v1/json?key=someopencageapikey&no_annotations=1&query=San%20Francisco,%20CA
|
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
|
+
Date:
|
22
|
+
- Wed, 03 Sep 2014 14:08:51 GMT
|
23
|
+
Server:
|
24
|
+
- Apache/2.4.7 (Ubuntu)
|
25
|
+
X-Ratelimit-Reset:
|
26
|
+
- '1409788800'
|
27
|
+
X-Ratelimit-Remaining:
|
28
|
+
- '2466'
|
29
|
+
X-Ratelimit-Limit:
|
30
|
+
- '2500'
|
31
|
+
Access-Control-Allow-Origin:
|
32
|
+
- '*'
|
33
|
+
Strict-Transport-Security:
|
34
|
+
- max-age=31536000; includeSubDomains
|
35
|
+
Transfer-Encoding:
|
36
|
+
- chunked
|
37
|
+
Content-Type:
|
38
|
+
- application/json; charset=utf-8
|
39
|
+
body:
|
40
|
+
encoding: UTF-8
|
41
|
+
string: '{"licenses":[{"name":"CC-BY-SA","url":"http://creativecommons.org/licenses/by-sa/3.0/"},{"name":"ODbL","url":"http://opendatacommons.org/licenses/odbl/summary/"}],"rate":{"limit":2500,"remaining":2466,"reset":1409788800},"results":[{"bounds":{"northeast":{"lat":37.9298443,"lng":-122.2817799},"southwest":{"lat":37.63983,"lng":-123.1738249}},"components":{"city":"San
|
42
|
+
Francisco","country":"United States of America","country_code":"US","county":"San
|
43
|
+
Francisco City and County","state":"California"},"confidence":1,"formatted":"San
|
44
|
+
Francisco, San Francisco City and County, California, United States of America","geometry":{"lat":37.7792768,"lng":-122.4192704}},{"bounds":{"northeast":{"lat":37.9298443,"lng":-122.2817799},"southwest":{"lat":37.63983,"lng":-123.1738249}},"components":{"country":"United
|
45
|
+
States of America","country_code":"US","county":"San Francisco City and County","state":"California"},"confidence":1,"formatted":"San
|
46
|
+
Francisco City and County, California, United States of America","geometry":{"lat":37.7647993,"lng":-122.4629897}}],"status":{"code":200,"message":"OK"},"thanks":"For
|
47
|
+
using an OpenCage Data API","timestamp":{"created_http":"Wed, 03 Sep 2014
|
48
|
+
14:08:51 GMT","created_unix":1409753331},"total_results":2,"we_are_hiring":"http://lokku.com/#jobs"}'
|
49
|
+
http_version:
|
50
|
+
recorded_at: Wed, 03 Sep 2014 14:03:54 GMT
|
51
|
+
recorded_with: VCR 2.9.2
|
@@ -0,0 +1,65 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: https://api.opencagedata.com/geocode/v1/json?key=someopencageapikey&no_annotations=1&query=100%20Spear%20St,%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
|
+
Date:
|
22
|
+
- Wed, 03 Sep 2014 13:51:27 GMT
|
23
|
+
Server:
|
24
|
+
- Apache/2.4.7 (Ubuntu)
|
25
|
+
Access-Control-Allow-Origin:
|
26
|
+
- '*'
|
27
|
+
X-Ratelimit-Remaining:
|
28
|
+
- '2468'
|
29
|
+
X-Ratelimit-Reset:
|
30
|
+
- '1409788800'
|
31
|
+
X-Ratelimit-Limit:
|
32
|
+
- '2500'
|
33
|
+
Strict-Transport-Security:
|
34
|
+
- max-age=31536000; includeSubDomains
|
35
|
+
Transfer-Encoding:
|
36
|
+
- chunked
|
37
|
+
Content-Type:
|
38
|
+
- application/json; charset=utf-8
|
39
|
+
body:
|
40
|
+
encoding: UTF-8
|
41
|
+
string: '{"licenses":[{"name":"CC-BY-SA","url":"http://creativecommons.org/licenses/by-sa/3.0/"},{"name":"ODbL","url":"http://opendatacommons.org/licenses/odbl/summary/"}],"rate":{"limit":2500,"remaining":2468,"reset":1409788800},"results":[{"bounds":{"northeast":{"lat":37.7923419,"lng":-122.394032},"southwest":{"lat":37.7922419,"lng":-122.394132}},"components":{"bank":"Wells
|
42
|
+
Fargo","city":"San Francisco","country":"United States of America","country_code":"US","county":"San
|
43
|
+
Francisco City and County","house_number":100,"neighbourhood":"Financial District","postcode":94103,"road":"Spear
|
44
|
+
Street","state":"California"},"confidence":10,"formatted":"100, Spear Street,
|
45
|
+
Financial District, San Francisco, San Francisco City and County, 94103, California,
|
46
|
+
United States of America, Wells Fargo","geometry":{"lat":37.7922919,"lng":-122.394082}},{"bounds":{"northeast":{"lat":37.7923695,"lng":-122.3937501},"southwest":{"lat":37.7919565,"lng":-122.3942877}},"components":{"city":"San
|
47
|
+
Francisco","country":"United States of America","country_code":"US","county":"San
|
48
|
+
Francisco City and County","house_number":100,"neighbourhood":"Financial District","postcode":94103,"road":"Spear
|
49
|
+
Street","state":"California"},"confidence":10,"formatted":"100, Spear Street,
|
50
|
+
Financial District, San Francisco, San Francisco City and County, 94103, California,
|
51
|
+
United States of America","geometry":{"lat":37.79215775,"lng":-122.393995576645}},{"bounds":{"northeast":{"lat":37.7923685,"lng":-122.3939964},"southwest":{"lat":37.7922685,"lng":-122.3940964}},"components":{"atm":"Wells
|
52
|
+
Fargo","city":"San Francisco","country":"United States of America","country_code":"US","county":"San
|
53
|
+
Francisco City and County","house_number":100,"neighbourhood":"Financial District","postcode":94103,"road":"Spear
|
54
|
+
Street","state":"California"},"confidence":10,"formatted":"100, Spear Street,
|
55
|
+
Financial District, San Francisco, San Francisco City and County, 94103, California,
|
56
|
+
United States of America, Wells Fargo","geometry":{"lat":37.7923185,"lng":-122.3940464}},{"components":{"country_name":"United
|
57
|
+
States","locality":"San Francisco","region":"CA","street_name":"Spear St","street_number":100},"confidence":0,"formatted":"San
|
58
|
+
Francisco, CA, United States, Spear St, 100","geometry":{"lat":37.792536,"lng":-122.39406}},{"bounds":{"northeast":{"lat":37.796628,"lng":-122.385181},"southwest":{"lat":37.784205,"lng":-122.403431}},"components":{"country":"United
|
59
|
+
States","county":"San Francisco County","postal code":94105,"state":"California"},"confidence":8,"formatted":"San
|
60
|
+
Francisco County, California, United States, 94105","geometry":{"lat":37.7864,"lng":-122.3892}}],"status":{"code":200,"message":"OK"},"thanks":"For
|
61
|
+
using an OpenCage Data API","timestamp":{"created_http":"Wed, 03 Sep 2014
|
62
|
+
13:51:27 GMT","created_unix":1409752287},"total_results":5,"we_are_hiring":"http://lokku.com/#jobs"}'
|
63
|
+
http_version:
|
64
|
+
recorded_at: Wed, 03 Sep 2014 13:46:30 GMT
|
65
|
+
recorded_with: VCR 2.9.2
|
@@ -0,0 +1,66 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: https://api.opencagedata.com/geocode/v1/json?key=someopencageapikey&language=es&no_annotations=1&query=London
|
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
|
+
Date:
|
22
|
+
- Wed, 03 Sep 2014 14:32:11 GMT
|
23
|
+
Server:
|
24
|
+
- Apache/2.4.7 (Ubuntu)
|
25
|
+
X-Ratelimit-Limit:
|
26
|
+
- '2500'
|
27
|
+
X-Ratelimit-Remaining:
|
28
|
+
- '2458'
|
29
|
+
X-Ratelimit-Reset:
|
30
|
+
- '1409788800'
|
31
|
+
Access-Control-Allow-Origin:
|
32
|
+
- '*'
|
33
|
+
Strict-Transport-Security:
|
34
|
+
- max-age=31536000; includeSubDomains
|
35
|
+
Transfer-Encoding:
|
36
|
+
- chunked
|
37
|
+
Content-Type:
|
38
|
+
- application/json; charset=utf-8
|
39
|
+
body:
|
40
|
+
encoding: UTF-8
|
41
|
+
string: '{"licenses":[{"name":"CC-BY-SA","url":"http://creativecommons.org/licenses/by-sa/3.0/"},{"name":"ODbL","url":"http://opendatacommons.org/licenses/odbl/summary/"}],"rate":{"limit":2500,"remaining":2458,"reset":1409788800},"results":[{"bounds":{"northeast":{"lat":51.6918741,"lng":0.3340155},"southwest":{"lat":51.2867602,"lng":-0.510375}},"components":{"city":"Londres","country":"Reino
|
42
|
+
Unido","country_code":"gb","county":"Londres","state":"Inglaterra","state_district":"Greater
|
43
|
+
London"},"confidence":1,"formatted":"Londres, Reino Unido","geometry":{"lat":51.5073219,"lng":-0.1276474}},{"bounds":{"northeast":{"lat":43.148097,"lng":-81.0860295},"southwest":{"lat":42.828097,"lng":-81.4060295}},"components":{"city":"London","country":"Canad\u00e1","country_code":"CA","state":"Ontario"},"confidence":3,"formatted":"London,
|
44
|
+
Ontario, Canad\u00e1","geometry":{"lat":42.988097,"lng":-81.2460295}},{"bounds":{"northeast":{"lat":37.15226,"lng":-84.0359569},"southwest":{"lat":37.079759,"lng":-84.1262619}},"components":{"city":"London","country":"Estados
|
45
|
+
Unidos de Am\u00e9rica","country_code":"US","county":"Laurel County","state":"Kentucky"},"confidence":7,"formatted":"London,
|
46
|
+
Laurel County, Kentucky, Estados Unidos de Am\u00e9rica","geometry":{"lat":37.1289771,"lng":-84.0832646}},{"bounds":{"northeast":{"lat":43.0677775,"lng":-88.9928881},"southwest":{"lat":43.0277775,"lng":-89.0328881}},"components":{"country":"Estados
|
47
|
+
Unidos de Am\u00e9rica","country_code":"US","county":"Dane County","hamlet":"London","state":"Wisconsin"},"confidence":7,"formatted":"London,
|
48
|
+
Dane County, Wisconsin, Estados Unidos de Am\u00e9rica","geometry":{"lat":43.0477775,"lng":-89.0128881}},{"bounds":{"northeast":{"lat":39.921786,"lng":-83.3899969},"southwest":{"lat":39.85928,"lng":-83.4789229}},"components":{"city":"London","country":"Estados
|
49
|
+
Unidos de Am\u00e9rica","country_code":"US","county":"Madison County","state":"Ohio"},"confidence":7,"formatted":"London,
|
50
|
+
Madison County, Ohio, Estados Unidos de Am\u00e9rica","geometry":{"lat":39.8864493,"lng":-83.448253}},{"bounds":{"northeast":{"lat":36.4884367,"lng":-119.4385394},"southwest":{"lat":36.4734452,"lng":-119.4497698}},"components":{"country":"Estados
|
51
|
+
Unidos de Am\u00e9rica","country_code":"US","county":"Tulare County","state":"California","village":"London"},"confidence":8,"formatted":"London,
|
52
|
+
Tulare County, California, Estados Unidos de Am\u00e9rica","geometry":{"lat":36.4760619,"lng":-119.4431785}},{"bounds":{"northeast":{"lat":35.33814,"lng":-93.1873749},"southwest":{"lat":35.315577,"lng":-93.2726929}},"components":{"city":"London","country":"Estados
|
53
|
+
Unidos de Am\u00e9rica","country_code":"US","county":"Pope County","state":"Arkansas"},"confidence":7,"formatted":"London,
|
54
|
+
Pope County, Arkansas, Estados Unidos de Am\u00e9rica","geometry":{"lat":35.326859,"lng":-93.2405016007635}},{"bounds":{"northeast":{"lat":38.2143567,"lng":-81.3486944},"southwest":{"lat":38.1743567,"lng":-81.3886944}},"components":{"country":"Estados
|
55
|
+
Unidos de Am\u00e9rica","country_code":"US","county":"Kanawha County","hamlet":"London","state":"Virginia
|
56
|
+
Occidental"},"confidence":7,"formatted":"London, Kanawha County, Virginia
|
57
|
+
Occidental, Estados Unidos de Am\u00e9rica","geometry":{"lat":38.1943567,"lng":-81.3686944}},{"bounds":{"northeast":{"lat":41.1636709,"lng":-80.1286716},"southwest":{"lat":41.1236709,"lng":-80.1686716}},"components":{"country":"Estados
|
58
|
+
Unidos de Am\u00e9rica","country_code":"US","county":"Mercer County","hamlet":"London","state":"Pensilvania"},"confidence":7,"formatted":"London,
|
59
|
+
Mercer County, Pensilvania, Estados Unidos de Am\u00e9rica","geometry":{"lat":41.1436709,"lng":-80.1486716}},{"bounds":{"northeast":{"lat":32.2509892,"lng":-94.9243839},"southwest":{"lat":32.2109892,"lng":-94.9643839}},"components":{"country":"Estados
|
60
|
+
Unidos de Am\u00e9rica","country_code":"US","county":"Rusk County","hamlet":"London","state":"Texas"},"confidence":7,"formatted":"London,
|
61
|
+
Rusk County, Texas, Estados Unidos de Am\u00e9rica","geometry":{"lat":32.2309892,"lng":-94.9443839}}],"status":{"code":200,"message":"OK"},"thanks":"For
|
62
|
+
using an OpenCage Data API","timestamp":{"created_http":"Wed, 03 Sep 2014
|
63
|
+
14:32:11 GMT","created_unix":1409754731},"total_results":10,"we_are_hiring":"http://lokku.com/#jobs"}'
|
64
|
+
http_version:
|
65
|
+
recorded_at: Wed, 03 Sep 2014 14:27:15 GMT
|
66
|
+
recorded_with: VCR 2.9.2
|
@@ -0,0 +1,51 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: https://api.opencagedata.com/geocode/v1/json?key=someopencageapikey&no_annotations=1&query=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
|
+
Date:
|
22
|
+
- Wed, 03 Sep 2014 14:12:59 GMT
|
23
|
+
Server:
|
24
|
+
- Apache/2.4.7 (Ubuntu)
|
25
|
+
Access-Control-Allow-Origin:
|
26
|
+
- '*'
|
27
|
+
X-Ratelimit-Limit:
|
28
|
+
- '2500'
|
29
|
+
X-Ratelimit-Remaining:
|
30
|
+
- '2465'
|
31
|
+
X-Ratelimit-Reset:
|
32
|
+
- '1409788800'
|
33
|
+
Strict-Transport-Security:
|
34
|
+
- max-age=31536000; includeSubDomains
|
35
|
+
Transfer-Encoding:
|
36
|
+
- chunked
|
37
|
+
Content-Type:
|
38
|
+
- application/json; charset=utf-8
|
39
|
+
body:
|
40
|
+
encoding: UTF-8
|
41
|
+
string: '{"licenses":[{"name":"CC-BY-SA","url":"http://creativecommons.org/licenses/by-sa/3.0/"},{"name":"ODbL","url":"http://opendatacommons.org/licenses/odbl/summary/"}],"rate":{"limit":2500,"remaining":2465,"reset":1409788800},"results":[{"bounds":{"northeast":{"lat":40.4679786,"lng":-3.6835385},"southwest":{"lat":40.4060007,"lng":-3.7033912}},"components":{"address29":"C-3
|
42
|
+
C-4","city":"Madrid","city_district":"Chamber\u00ed","country":"Spain","country_code":"ES","county":"\u00c1rea
|
43
|
+
metropolitana de Madrid y Corredor del Henares","postcode":28036,"road":"Calle
|
44
|
+
de Zurbano","state":"Community of Madrid","suburb":"Chamber\u00ed"},"confidence":7,"formatted":"Calle
|
45
|
+
de Zurbano, Chamber\u00ed, Chamber\u00ed, Madrid, \u00c1rea metropolitana
|
46
|
+
de Madrid y Corredor del Henares, 28036, Community of Madrid, Spain, C-3 C-4","geometry":{"lat":40.4341975,"lng":-3.6930528}}],"status":{"code":200,"message":"OK"},"thanks":"For
|
47
|
+
using an OpenCage Data API","timestamp":{"created_http":"Wed, 03 Sep 2014
|
48
|
+
14:12:59 GMT","created_unix":1409753579},"total_results":1,"we_are_hiring":"http://lokku.com/#jobs"}'
|
49
|
+
http_version:
|
50
|
+
recorded_at: Wed, 03 Sep 2014 14:08:02 GMT
|
51
|
+
recorded_with: VCR 2.9.2
|
@@ -0,0 +1,53 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: https://api.opencagedata.com/geocode/v1/json?key=someopencageapikey&no_annotations=1&query=41.3527177,21.5497808
|
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
|
+
Date:
|
22
|
+
- Wed, 03 Sep 2014 14:19:24 GMT
|
23
|
+
Server:
|
24
|
+
- Apache/2.4.7 (Ubuntu)
|
25
|
+
X-Ratelimit-Remaining:
|
26
|
+
- '2463'
|
27
|
+
X-Ratelimit-Reset:
|
28
|
+
- '1409788800'
|
29
|
+
X-Ratelimit-Limit:
|
30
|
+
- '2500'
|
31
|
+
Access-Control-Allow-Origin:
|
32
|
+
- '*'
|
33
|
+
Strict-Transport-Security:
|
34
|
+
- max-age=31536000; includeSubDomains
|
35
|
+
Transfer-Encoding:
|
36
|
+
- chunked
|
37
|
+
Content-Type:
|
38
|
+
- application/json; charset=utf-8
|
39
|
+
body:
|
40
|
+
encoding: UTF-8
|
41
|
+
string: '{"licenses":[{"name":"CC-BY-SA","url":"http://creativecommons.org/licenses/by-sa/3.0/"},{"name":"ODbL","url":"http://opendatacommons.org/licenses/odbl/summary/"}],"rate":{"limit":2500,"remaining":2463,"reset":1409788800},"results":[{"bounds":{"northeast":{"lat":41.3516718,"lng":21.5508583},"southwest":{"lat":41.350177,"lng":21.54897}},"components":{"city":"Prilep","country":"Macedonia","country_code":"MK","county":"Municipality
|
42
|
+
of Prilep","neighbourhood":"\u0416\u0430\u0431\u0438\u043d\u043e \u041c\u0430\u0430\u043b\u043e","road":"\u041f\u0440\u0438\u043b\u0435\u043f\u0441\u043a\u0438
|
43
|
+
\u0411\u0440\u0430\u043d\u0438\u0442\u0435\u043b\u0438","school":"Gimnasium Mirche
|
44
|
+
Acev","state":"Pelagonia Region","suburb":"\u0411\u043e\u043d\u0447\u0435\u0458\u0446\u0430"},"confidence":10,"formatted":"Gimnasium
|
45
|
+
Mirche Acev, \u041f\u0440\u0438\u043b\u0435\u043f\u0441\u043a\u0438 \u0411\u0440\u0430\u043d\u0438\u0442\u0435\u043b\u0438,
|
46
|
+
\u0411\u043e\u043d\u0447\u0435\u0458\u0446\u0430, \u0416\u0430\u0431\u0438\u043d\u043e
|
47
|
+
\u041c\u0430\u0430\u043b\u043e, Prilep, Municipality of Prilep, Pelagonia
|
48
|
+
Region, Macedonia, Gimnasium Mirche Acev","geometry":{"lat":41.35125945,"lng":21.5498645766622}}],"status":{"code":200,"message":"OK"},"thanks":"For
|
49
|
+
using an OpenCage Data API","timestamp":{"created_http":"Wed, 03 Sep 2014
|
50
|
+
14:19:24 GMT","created_unix":1409753964},"total_results":1,"we_are_hiring":"http://lokku.com/#jobs"}'
|
51
|
+
http_version:
|
52
|
+
recorded_at: Wed, 03 Sep 2014 14:14:27 GMT
|
53
|
+
recorded_with: VCR 2.9.2
|
data/geokit.gemspec
CHANGED
@@ -22,13 +22,15 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
23
23
|
spec.require_paths = ["lib"]
|
24
24
|
|
25
|
-
spec.add_dependency
|
26
|
-
spec.add_development_dependency
|
25
|
+
spec.add_dependency 'multi_json', '>= 1.3.2'
|
26
|
+
spec.add_development_dependency 'bundler', '> 1.0'
|
27
27
|
spec.add_development_dependency 'simplecov'
|
28
|
-
spec.add_development_dependency
|
28
|
+
spec.add_development_dependency 'simplecov-rcov'
|
29
29
|
spec.add_development_dependency 'rake'
|
30
30
|
spec.add_development_dependency 'mocha'
|
31
31
|
spec.add_development_dependency 'coveralls'
|
32
|
+
spec.add_development_dependency 'rubocop'
|
33
|
+
spec.add_development_dependency 'pre-commit'
|
32
34
|
spec.add_development_dependency 'vcr'
|
33
35
|
spec.add_development_dependency 'webmock' # used in vcr
|
34
36
|
spec.add_development_dependency 'typhoeus' # used in net_adapter
|
data/lib/geokit/bounds.rb
CHANGED
@@ -5,19 +5,21 @@ module Geokit
|
|
5
5
|
attr_accessor :sw, :ne
|
6
6
|
|
7
7
|
# provide sw and ne to instantiate a new Bounds instance
|
8
|
-
def initialize(sw,ne)
|
9
|
-
|
10
|
-
|
8
|
+
def initialize(sw, ne)
|
9
|
+
if !(sw.is_a?(Geokit::LatLng) && ne.is_a?(Geokit::LatLng))
|
10
|
+
raise ArgumentError
|
11
|
+
end
|
12
|
+
@sw, @ne = sw, ne
|
11
13
|
end
|
12
14
|
|
13
|
-
#returns the a single point which is the center of the rectangular bounds
|
15
|
+
# returns the a single point which is the center of the rectangular bounds
|
14
16
|
def center
|
15
17
|
@sw.midpoint_to(@ne)
|
16
18
|
end
|
17
19
|
|
18
20
|
# a simple string representation:sw,ne
|
19
21
|
def to_s
|
20
|
-
"#{@sw
|
22
|
+
"#{@sw},#{@ne}"
|
21
23
|
end
|
22
24
|
|
23
25
|
# a two-element array of two-element arrays: sw,ne
|
@@ -28,7 +30,7 @@ module Geokit
|
|
28
30
|
# Returns true if the bounds contain the passed point.
|
29
31
|
# allows for bounds which cross the meridian
|
30
32
|
def contains?(point)
|
31
|
-
point=Geokit::LatLng.normalize(point)
|
33
|
+
point = Geokit::LatLng.normalize(point)
|
32
34
|
res = point.lat > @sw.lat && point.lat < @ne.lat
|
33
35
|
if crosses_meridian?
|
34
36
|
res &= point.lng < @ne.lng || point.lng > @sw.lng
|
@@ -43,8 +45,9 @@ module Geokit
|
|
43
45
|
@sw.lng > @ne.lng
|
44
46
|
end
|
45
47
|
|
46
|
-
# Returns true if the candidate object is logically equal.
|
47
|
-
# is true if the lat and lng attributes are the same for both
|
48
|
+
# Returns true if the candidate object is logically equal. Logical
|
49
|
+
# equivalence is true if the lat and lng attributes are the same for both
|
50
|
+
# objects.
|
48
51
|
def ==(other)
|
49
52
|
return false unless other.is_a?(Bounds)
|
50
53
|
sw == other.sw && ne == other.ne
|
@@ -52,44 +55,50 @@ module Geokit
|
|
52
55
|
|
53
56
|
# Equivalent to Google Maps API's .toSpan() method on GLatLng's.
|
54
57
|
#
|
55
|
-
# Returns a LatLng object, whose coordinates represent the size of a
|
56
|
-
# defined by these bounds.
|
58
|
+
# Returns a LatLng object, whose coordinates represent the size of a
|
59
|
+
# rectangle defined by these bounds.
|
57
60
|
def to_span
|
58
|
-
lat_span =
|
59
|
-
lng_span =
|
60
|
-
Geokit::LatLng.new(lat_span, lng_span)
|
61
|
+
lat_span = @ne.lat - @sw.lat
|
62
|
+
lng_span = crosses_meridian? ? 360 + @ne.lng - @sw.lng : @ne.lng - @sw.lng
|
63
|
+
Geokit::LatLng.new(lat_span.abs, lng_span.abs)
|
61
64
|
end
|
62
65
|
|
63
66
|
class <<self
|
64
|
-
|
65
|
-
#
|
66
|
-
def from_point_and_radius(point,radius,options={})
|
67
|
-
point=LatLng.normalize(point)
|
68
|
-
p0=point.endpoint(0,radius,options)
|
69
|
-
p90=point.endpoint(90,radius,options)
|
70
|
-
p180=point.endpoint(180,radius,options)
|
71
|
-
p270=point.endpoint(270,radius,options)
|
72
|
-
sw=Geokit::LatLng.new(p180.lat,p270.lng)
|
73
|
-
ne=Geokit::LatLng.new(p0.lat,p90.lng)
|
74
|
-
Geokit::Bounds.new(sw,ne)
|
67
|
+
# returns an instance of bounds which completely encompases the given
|
68
|
+
# circle
|
69
|
+
def from_point_and_radius(point, radius, options = {})
|
70
|
+
point = LatLng.normalize(point)
|
71
|
+
p0 = point.endpoint(0, radius, options)
|
72
|
+
p90 = point.endpoint(90, radius, options)
|
73
|
+
p180 = point.endpoint(180, radius, options)
|
74
|
+
p270 = point.endpoint(270, radius, options)
|
75
|
+
sw = Geokit::LatLng.new(p180.lat, p270.lng)
|
76
|
+
ne = Geokit::LatLng.new(p0.lat, p90.lng)
|
77
|
+
Geokit::Bounds.new(sw, ne)
|
75
78
|
end
|
76
79
|
|
77
80
|
# Takes two main combinations of arguments to create a bounds:
|
78
81
|
# point,point (this is the only one which takes two arguments
|
79
82
|
# [point,point]
|
80
|
-
# . . . where a point is anything LatLng#normalize can handle
|
83
|
+
# . . . where a point is anything LatLng#normalize can handle
|
84
|
+
# (which is quite a lot)
|
81
85
|
#
|
82
|
-
# NOTE: everything combination is assumed to pass points in the order
|
83
|
-
|
84
|
-
|
86
|
+
# NOTE: everything combination is assumed to pass points in the order
|
87
|
+
# sw, ne
|
88
|
+
def normalize (thing, other = nil)
|
89
|
+
# maybe this will be simple -- an actual bounds object is passed, and
|
90
|
+
# we can all go home
|
85
91
|
return thing if thing.is_a? Bounds
|
86
92
|
|
87
93
|
# no? OK, if there's no "other," the thing better be a two-element array
|
88
|
-
thing,other=thing if !other && thing.is_a?(Array) && thing.size==2
|
94
|
+
thing, other = thing if !other && thing.is_a?(Array) && thing.size == 2
|
89
95
|
|
90
|
-
# Now that we're set with a thing and another thing, let LatLng do the
|
96
|
+
# Now that we're set with a thing and another thing, let LatLng do the
|
97
|
+
# heavy lifting.
|
91
98
|
# Exceptions may be thrown
|
92
|
-
|
99
|
+
thing_ll = Geokit::LatLng.normalize(thing)
|
100
|
+
other_ll = Geokit::LatLng.normalize(other)
|
101
|
+
Bounds.new(thing_ll, other_ll)
|
93
102
|
end
|
94
103
|
end
|
95
104
|
end
|