geocoder 1.2.6 → 1.8.2
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.
- checksums.yaml +5 -5
- data/CHANGELOG.md +266 -1
- data/LICENSE +1 -1
- data/README.md +530 -804
- data/bin/console +13 -0
- data/examples/app_defined_lookup_services.rb +22 -0
- data/examples/reverse_geocode_job.rb +40 -0
- data/lib/easting_northing.rb +171 -0
- data/lib/generators/geocoder/config/templates/initializer.rb +22 -16
- data/lib/generators/geocoder/maxmind/geolite_city_generator.rb +2 -0
- data/lib/generators/geocoder/maxmind/geolite_country_generator.rb +2 -0
- data/lib/generators/geocoder/maxmind/templates/migration/geolite_city.rb +1 -1
- data/lib/generators/geocoder/maxmind/templates/migration/geolite_country.rb +1 -1
- data/lib/generators/geocoder/migration_version.rb +15 -0
- data/lib/geocoder/cache.rb +20 -33
- data/lib/geocoder/cache_stores/base.rb +40 -0
- data/lib/geocoder/cache_stores/generic.rb +35 -0
- data/lib/geocoder/cache_stores/redis.rb +34 -0
- data/lib/geocoder/calculations.rb +30 -38
- data/lib/geocoder/cli.rb +2 -2
- data/lib/geocoder/configuration.rb +36 -9
- data/lib/geocoder/configuration_hash.rb +4 -4
- data/lib/geocoder/esri_token.rb +38 -0
- data/lib/geocoder/exceptions.rb +19 -0
- data/lib/geocoder/ip_address.rb +26 -11
- data/lib/geocoder/kernel_logger.rb +25 -0
- data/lib/geocoder/logger.rb +47 -0
- data/lib/geocoder/lookup.rb +63 -13
- data/lib/geocoder/lookups/abstract_api.rb +46 -0
- data/lib/geocoder/lookups/amap.rb +63 -0
- data/lib/geocoder/lookups/amazon_location_service.rb +55 -0
- data/lib/geocoder/lookups/baidu.rb +17 -9
- data/lib/geocoder/lookups/baidu_ip.rb +7 -31
- data/lib/geocoder/lookups/ban_data_gouv_fr.rb +143 -0
- data/lib/geocoder/lookups/base.rb +75 -26
- data/lib/geocoder/lookups/bing.rb +38 -15
- data/lib/geocoder/lookups/db_ip_com.rb +52 -0
- data/lib/geocoder/lookups/dstk.rb +4 -2
- data/lib/geocoder/lookups/esri.rb +78 -12
- data/lib/geocoder/lookups/freegeoip.rb +22 -7
- data/lib/geocoder/lookups/geoapify.rb +78 -0
- data/lib/geocoder/lookups/geocoder_ca.rb +5 -6
- data/lib/geocoder/lookups/geocodio.rb +8 -8
- data/lib/geocoder/lookups/geoip2.rb +13 -4
- data/lib/geocoder/lookups/geoportail_lu.rb +65 -0
- data/lib/geocoder/lookups/google.rb +44 -11
- data/lib/geocoder/lookups/google_places_details.rb +31 -17
- data/lib/geocoder/lookups/google_places_search.rb +76 -0
- data/lib/geocoder/lookups/google_premier.rb +15 -1
- data/lib/geocoder/lookups/here.rb +38 -27
- data/lib/geocoder/lookups/ip2location.rb +71 -0
- data/lib/geocoder/lookups/ipapi_com.rb +82 -0
- data/lib/geocoder/lookups/ipbase.rb +49 -0
- data/lib/geocoder/lookups/ipdata_co.rb +62 -0
- data/lib/geocoder/lookups/ipgeolocation.rb +51 -0
- data/lib/geocoder/lookups/ipinfo_io.rb +44 -0
- data/lib/geocoder/lookups/ipqualityscore.rb +50 -0
- data/lib/geocoder/lookups/ipregistry.rb +68 -0
- data/lib/geocoder/lookups/ipstack.rb +63 -0
- data/lib/geocoder/lookups/latlon.rb +58 -0
- data/lib/geocoder/lookups/location_iq.rb +54 -0
- data/lib/geocoder/lookups/mapbox.rb +59 -0
- data/lib/geocoder/lookups/mapquest.rb +7 -9
- data/lib/geocoder/lookups/maxmind.rb +7 -7
- data/lib/geocoder/lookups/maxmind_geoip2.rb +70 -0
- data/lib/geocoder/lookups/maxmind_local.rb +16 -3
- data/lib/geocoder/lookups/melissa_street.rb +41 -0
- data/lib/geocoder/lookups/nationaal_georegister_nl.rb +38 -0
- data/lib/geocoder/lookups/nominatim.rb +18 -6
- data/lib/geocoder/lookups/opencagedata.rb +16 -9
- data/lib/geocoder/lookups/osmnames.rb +57 -0
- data/lib/geocoder/lookups/pc_miler.rb +85 -0
- data/lib/geocoder/lookups/pelias.rb +63 -0
- data/lib/geocoder/lookups/photon.rb +89 -0
- data/lib/geocoder/lookups/pickpoint.rb +41 -0
- data/lib/geocoder/lookups/pointpin.rb +14 -13
- data/lib/geocoder/lookups/postcode_anywhere_uk.rb +7 -8
- data/lib/geocoder/lookups/postcodes_io.rb +31 -0
- data/lib/geocoder/lookups/smarty_streets.rb +29 -6
- data/lib/geocoder/lookups/telize.rb +42 -7
- data/lib/geocoder/lookups/tencent.rb +59 -0
- data/lib/geocoder/lookups/test.rb +5 -0
- data/lib/geocoder/lookups/twogis.rb +58 -0
- data/lib/geocoder/lookups/uk_ordnance_survey_names.rb +59 -0
- data/lib/geocoder/lookups/yandex.rb +20 -13
- data/lib/geocoder/models/active_record.rb +4 -3
- data/lib/geocoder/models/mongo_base.rb +0 -2
- data/lib/geocoder/query.rb +15 -1
- data/lib/geocoder/railtie.rb +1 -1
- data/lib/geocoder/request.rb +103 -14
- data/lib/geocoder/results/abstract_api.rb +146 -0
- data/lib/geocoder/results/amap.rb +87 -0
- data/lib/geocoder/results/amazon_location_service.rb +57 -0
- data/lib/geocoder/results/baidu.rb +10 -14
- data/lib/geocoder/results/ban_data_gouv_fr.rb +282 -0
- data/lib/geocoder/results/base.rb +13 -1
- data/lib/geocoder/results/bing.rb +5 -1
- data/lib/geocoder/results/db_ip_com.rb +58 -0
- data/lib/geocoder/results/esri.rb +35 -8
- data/lib/geocoder/results/freegeoip.rb +2 -7
- data/lib/geocoder/results/geoapify.rb +179 -0
- data/lib/geocoder/results/geocoder_ca.rb +3 -3
- data/lib/geocoder/results/geocodio.rb +15 -3
- data/lib/geocoder/results/geoip2.rb +37 -25
- data/lib/geocoder/results/geoportail_lu.rb +71 -0
- data/lib/geocoder/results/google.rb +26 -0
- data/lib/geocoder/results/google_places_details.rb +4 -0
- data/lib/geocoder/results/google_places_search.rb +52 -0
- data/lib/geocoder/results/here.rb +30 -15
- data/lib/geocoder/results/ip2location.rb +22 -0
- data/lib/geocoder/results/ipapi_com.rb +45 -0
- data/lib/geocoder/results/ipbase.rb +40 -0
- data/lib/geocoder/results/ipdata_co.rb +40 -0
- data/lib/geocoder/results/ipgeolocation.rb +59 -0
- data/lib/geocoder/results/ipinfo_io.rb +48 -0
- data/lib/geocoder/results/ipqualityscore.rb +54 -0
- data/lib/geocoder/results/ipregistry.rb +304 -0
- data/lib/geocoder/results/ipstack.rb +60 -0
- data/lib/geocoder/results/latlon.rb +71 -0
- data/lib/geocoder/results/location_iq.rb +6 -0
- data/lib/geocoder/results/mapbox.rb +63 -0
- data/lib/geocoder/results/mapquest.rb +5 -8
- data/lib/geocoder/results/maxmind.rb +0 -5
- data/lib/geocoder/results/maxmind_geoip2.rb +9 -0
- data/lib/geocoder/results/maxmind_local.rb +0 -5
- data/lib/geocoder/results/melissa_street.rb +46 -0
- data/lib/geocoder/results/nationaal_georegister_nl.rb +62 -0
- data/lib/geocoder/results/nominatim.rb +41 -14
- data/lib/geocoder/results/opencagedata.rb +20 -2
- data/lib/geocoder/results/osmnames.rb +56 -0
- data/lib/geocoder/results/pc_miler.rb +98 -0
- data/lib/geocoder/results/pelias.rb +58 -0
- data/lib/geocoder/results/photon.rb +119 -0
- data/lib/geocoder/results/pickpoint.rb +6 -0
- data/lib/geocoder/results/pointpin.rb +0 -4
- data/lib/geocoder/results/postcodes_io.rb +40 -0
- data/lib/geocoder/results/smarty_streets.rb +55 -19
- data/lib/geocoder/results/telize.rb +0 -5
- data/lib/geocoder/results/tencent.rb +72 -0
- data/lib/geocoder/results/test.rb +1 -1
- data/lib/geocoder/results/twogis.rb +76 -0
- data/lib/geocoder/results/uk_ordnance_survey_names.rb +59 -0
- data/lib/geocoder/results/yandex.rb +240 -32
- data/lib/geocoder/sql.rb +9 -6
- data/lib/geocoder/stores/active_record.rb +49 -10
- data/lib/geocoder/stores/base.rb +2 -14
- data/lib/geocoder/stores/mongo_base.rb +0 -31
- data/lib/geocoder/util.rb +29 -0
- data/lib/geocoder/version.rb +1 -1
- data/lib/geocoder.rb +2 -1
- data/lib/maxmind_database.rb +9 -9
- data/lib/tasks/geocoder.rake +29 -4
- data/lib/tasks/maxmind.rake +1 -1
- metadata +91 -169
- data/.gitignore +0 -6
- data/.travis.yml +0 -31
- data/Rakefile +0 -25
- data/examples/autoexpire_cache_dalli.rb +0 -62
- data/examples/autoexpire_cache_redis.rb +0 -28
- data/gemfiles/Gemfile.mongoid-2.4.x +0 -16
- data/lib/geocoder/lookups/geocoder_us.rb +0 -39
- data/lib/geocoder/lookups/okf.rb +0 -43
- data/lib/geocoder/lookups/ovi.rb +0 -62
- data/lib/geocoder/lookups/yahoo.rb +0 -88
- data/lib/geocoder/results/geocoder_us.rb +0 -39
- data/lib/geocoder/results/okf.rb +0 -106
- data/lib/geocoder/results/ovi.rb +0 -62
- data/lib/geocoder/results/yahoo.rb +0 -55
- data/lib/hash_recursive_merge.rb +0 -74
- data/lib/oauth_util.rb +0 -112
- data/test/fixtures/baidu_invalid_key +0 -1
- data/test/fixtures/baidu_ip_202_198_16_3 +0 -19
- data/test/fixtures/baidu_ip_invalid_key +0 -1
- data/test/fixtures/baidu_ip_no_results +0 -1
- data/test/fixtures/baidu_no_results +0 -1
- data/test/fixtures/baidu_reverse +0 -1
- data/test/fixtures/baidu_shanghai_pearl_tower +0 -12
- data/test/fixtures/bing_invalid_key +0 -1
- data/test/fixtures/bing_madison_square_garden +0 -40
- data/test/fixtures/bing_no_results +0 -16
- data/test/fixtures/bing_reverse +0 -42
- data/test/fixtures/cloudmade_invalid_key +0 -1
- data/test/fixtures/cloudmade_madison_square_garden +0 -1
- data/test/fixtures/cloudmade_no_results +0 -1
- data/test/fixtures/esri_madison_square_garden +0 -59
- data/test/fixtures/esri_no_results +0 -8
- data/test/fixtures/esri_reverse +0 -21
- data/test/fixtures/freegeoip_74_200_247_59 +0 -12
- data/test/fixtures/freegeoip_no_results +0 -1
- data/test/fixtures/geocoder_ca_madison_square_garden +0 -1
- data/test/fixtures/geocoder_ca_no_results +0 -1
- data/test/fixtures/geocoder_ca_reverse +0 -34
- data/test/fixtures/geocoder_us_madison_square_garden +0 -1
- data/test/fixtures/geocoder_us_no_results +0 -1
- data/test/fixtures/geocodio_1101_pennsylvania_ave +0 -1
- data/test/fixtures/geocodio_bad_api_key +0 -3
- data/test/fixtures/geocodio_invalid +0 -4
- data/test/fixtures/geocodio_no_results +0 -1
- data/test/fixtures/geocodio_over_query_limit +0 -4
- data/test/fixtures/google_garbage +0 -456
- data/test/fixtures/google_madison_square_garden +0 -57
- data/test/fixtures/google_no_city_data +0 -44
- data/test/fixtures/google_no_locality +0 -51
- data/test/fixtures/google_no_results +0 -4
- data/test/fixtures/google_over_limit +0 -4
- data/test/fixtures/google_places_details_invalid_request +0 -4
- data/test/fixtures/google_places_details_madison_square_garden +0 -120
- data/test/fixtures/google_places_details_no_results +0 -4
- data/test/fixtures/google_places_details_no_reviews +0 -60
- data/test/fixtures/google_places_details_no_types +0 -66
- data/test/fixtures/here_madison_square_garden +0 -72
- data/test/fixtures/here_no_results +0 -8
- data/test/fixtures/mapquest_error +0 -16
- data/test/fixtures/mapquest_invalid_api_key +0 -16
- data/test/fixtures/mapquest_invalid_request +0 -16
- data/test/fixtures/mapquest_madison_square_garden +0 -52
- data/test/fixtures/mapquest_no_results +0 -16
- data/test/fixtures/maxmind_24_24_24_21 +0 -1
- data/test/fixtures/maxmind_24_24_24_22 +0 -1
- data/test/fixtures/maxmind_24_24_24_23 +0 -1
- data/test/fixtures/maxmind_24_24_24_24 +0 -1
- data/test/fixtures/maxmind_74_200_247_59 +0 -1
- data/test/fixtures/maxmind_invalid_key +0 -1
- data/test/fixtures/maxmind_no_results +0 -1
- data/test/fixtures/nominatim_madison_square_garden +0 -150
- data/test/fixtures/nominatim_no_results +0 -1
- data/test/fixtures/nominatim_over_limit +0 -1
- data/test/fixtures/okf_kirstinmaki +0 -67
- data/test/fixtures/okf_no_results +0 -4
- data/test/fixtures/opencagedata_invalid_api_key +0 -25
- data/test/fixtures/opencagedata_invalid_request +0 -26
- data/test/fixtures/opencagedata_madison_square_garden +0 -73
- data/test/fixtures/opencagedata_no_results +0 -29
- data/test/fixtures/opencagedata_over_limit +0 -31
- data/test/fixtures/ovi_madison_square_garden +0 -72
- data/test/fixtures/ovi_no_results +0 -8
- data/test/fixtures/pointpin_10_10_10_10 +0 -1
- data/test/fixtures/pointpin_555_555_555_555 +0 -1
- data/test/fixtures/pointpin_80_111_555_555 +0 -1
- data/test/fixtures/pointpin_no_results +0 -1
- data/test/fixtures/postcode_anywhere_uk_geocode_v2_00_WR26NJ +0 -1
- data/test/fixtures/postcode_anywhere_uk_geocode_v2_00_generic_error +0 -1
- data/test/fixtures/postcode_anywhere_uk_geocode_v2_00_hampshire +0 -1
- data/test/fixtures/postcode_anywhere_uk_geocode_v2_00_key_limit_exceeded +0 -1
- data/test/fixtures/postcode_anywhere_uk_geocode_v2_00_no_results +0 -1
- data/test/fixtures/postcode_anywhere_uk_geocode_v2_00_romsey +0 -1
- data/test/fixtures/postcode_anywhere_uk_geocode_v2_00_unknown_key +0 -1
- data/test/fixtures/smarty_streets_11211 +0 -1
- data/test/fixtures/smarty_streets_madison_square_garden +0 -47
- data/test/fixtures/smarty_streets_no_results +0 -1
- data/test/fixtures/telize_10_10_10_10 +0 -1
- data/test/fixtures/telize_555_555_555_555 +0 -4
- data/test/fixtures/telize_74_200_247_59 +0 -1
- data/test/fixtures/telize_no_results +0 -1
- data/test/fixtures/yahoo_error +0 -1
- data/test/fixtures/yahoo_invalid_key +0 -2
- data/test/fixtures/yahoo_madison_square_garden +0 -52
- data/test/fixtures/yahoo_no_results +0 -10
- data/test/fixtures/yahoo_over_limit +0 -2
- data/test/fixtures/yandex_canada_rue_dupuis_14 +0 -446
- data/test/fixtures/yandex_invalid_key +0 -1
- data/test/fixtures/yandex_kremlin +0 -48
- data/test/fixtures/yandex_new_york +0 -1
- data/test/fixtures/yandex_no_city_and_town +0 -112
- data/test/fixtures/yandex_no_results +0 -16
- data/test/integration/http_client_test.rb +0 -31
- data/test/mongoid_test_helper.rb +0 -43
- data/test/test_helper.rb +0 -416
- data/test/unit/active_record_test.rb +0 -16
- data/test/unit/cache_test.rb +0 -37
- data/test/unit/calculations_test.rb +0 -220
- data/test/unit/configuration_test.rb +0 -55
- data/test/unit/error_handling_test.rb +0 -56
- data/test/unit/geocoder_test.rb +0 -78
- data/test/unit/https_test.rb +0 -17
- data/test/unit/ip_address_test.rb +0 -27
- data/test/unit/lookup_test.rb +0 -153
- data/test/unit/lookups/bing_test.rb +0 -68
- data/test/unit/lookups/dstk_test.rb +0 -26
- data/test/unit/lookups/esri_test.rb +0 -48
- data/test/unit/lookups/freegeoip_test.rb +0 -27
- data/test/unit/lookups/geocoder_ca_test.rb +0 -17
- data/test/unit/lookups/geocodio_test.rb +0 -55
- data/test/unit/lookups/geoip2_test.rb +0 -27
- data/test/unit/lookups/google_places_details_test.rb +0 -122
- data/test/unit/lookups/google_premier_test.rb +0 -22
- data/test/unit/lookups/google_test.rb +0 -84
- data/test/unit/lookups/mapquest_test.rb +0 -60
- data/test/unit/lookups/maxmind_local_test.rb +0 -28
- data/test/unit/lookups/maxmind_test.rb +0 -63
- data/test/unit/lookups/nominatim_test.rb +0 -31
- data/test/unit/lookups/okf_test.rb +0 -38
- data/test/unit/lookups/opencagedata_test.rb +0 -64
- data/test/unit/lookups/pointpin_test.rb +0 -30
- data/test/unit/lookups/postcode_anywhere_uk_test.rb +0 -70
- data/test/unit/lookups/smarty_streets_test.rb +0 -71
- data/test/unit/lookups/telize_test.rb +0 -36
- data/test/unit/lookups/yahoo_test.rb +0 -35
- data/test/unit/method_aliases_test.rb +0 -26
- data/test/unit/model_test.rb +0 -38
- data/test/unit/mongoid_test.rb +0 -47
- data/test/unit/near_test.rb +0 -87
- data/test/unit/oauth_util_test.rb +0 -31
- data/test/unit/proxy_test.rb +0 -37
- data/test/unit/query_test.rb +0 -52
- data/test/unit/rake_task_test.rb +0 -21
- data/test/unit/request_test.rb +0 -35
- data/test/unit/result_test.rb +0 -72
- data/test/unit/test_mode_test.rb +0 -70
|
@@ -4,14 +4,12 @@ module Geocoder::Result
|
|
|
4
4
|
class Nominatim < Base
|
|
5
5
|
|
|
6
6
|
def poi
|
|
7
|
-
|
|
8
|
-
return @data['address'][key] if @data['address'].key?(key)
|
|
9
|
-
end
|
|
7
|
+
return address_data[place_type] if address_data.key?(place_type)
|
|
10
8
|
return nil
|
|
11
9
|
end
|
|
12
10
|
|
|
13
11
|
def house_number
|
|
14
|
-
|
|
12
|
+
address_data['house_number']
|
|
15
13
|
end
|
|
16
14
|
|
|
17
15
|
def address
|
|
@@ -20,53 +18,71 @@ module Geocoder::Result
|
|
|
20
18
|
|
|
21
19
|
def street
|
|
22
20
|
%w[road pedestrian highway].each do |key|
|
|
23
|
-
return
|
|
21
|
+
return address_data[key] if address_data.key?(key)
|
|
24
22
|
end
|
|
25
23
|
return nil
|
|
26
24
|
end
|
|
27
25
|
|
|
28
26
|
def city
|
|
29
27
|
%w[city town village hamlet].each do |key|
|
|
30
|
-
return
|
|
28
|
+
return address_data[key] if address_data.key?(key)
|
|
31
29
|
end
|
|
32
30
|
return nil
|
|
33
31
|
end
|
|
34
32
|
|
|
35
33
|
def village
|
|
36
|
-
|
|
34
|
+
address_data['village']
|
|
37
35
|
end
|
|
38
36
|
|
|
39
37
|
def town
|
|
40
|
-
|
|
38
|
+
address_data['town']
|
|
41
39
|
end
|
|
42
40
|
|
|
43
41
|
def state
|
|
44
|
-
|
|
42
|
+
address_data['state']
|
|
45
43
|
end
|
|
46
44
|
|
|
47
45
|
alias_method :state_code, :state
|
|
48
46
|
|
|
49
47
|
def postal_code
|
|
50
|
-
|
|
48
|
+
address_data['postcode']
|
|
51
49
|
end
|
|
52
50
|
|
|
53
51
|
def county
|
|
54
|
-
|
|
52
|
+
address_data['county']
|
|
55
53
|
end
|
|
56
54
|
|
|
57
55
|
def country
|
|
58
|
-
|
|
56
|
+
address_data['country']
|
|
59
57
|
end
|
|
60
58
|
|
|
61
59
|
def country_code
|
|
62
|
-
|
|
60
|
+
address_data['country_code']
|
|
63
61
|
end
|
|
64
62
|
|
|
65
63
|
def suburb
|
|
66
|
-
|
|
64
|
+
address_data['suburb']
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def city_district
|
|
68
|
+
address_data['city_district']
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def state_district
|
|
72
|
+
address_data['state_district']
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def neighbourhood
|
|
76
|
+
address_data['neighbourhood']
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def municipality
|
|
80
|
+
address_data['municipality']
|
|
67
81
|
end
|
|
68
82
|
|
|
69
83
|
def coordinates
|
|
84
|
+
return [] unless @data['lat'] && @data['lon']
|
|
85
|
+
|
|
70
86
|
[@data['lat'].to_f, @data['lon'].to_f]
|
|
71
87
|
end
|
|
72
88
|
|
|
@@ -78,6 +94,11 @@ module Geocoder::Result
|
|
|
78
94
|
@data['type']
|
|
79
95
|
end
|
|
80
96
|
|
|
97
|
+
def viewport
|
|
98
|
+
south, north, west, east = @data['boundingbox'].map(&:to_f)
|
|
99
|
+
[south, west, north, east]
|
|
100
|
+
end
|
|
101
|
+
|
|
81
102
|
def self.response_attributes
|
|
82
103
|
%w[place_id osm_type osm_id boundingbox license
|
|
83
104
|
polygonpoints display_name class type stadium]
|
|
@@ -90,5 +111,11 @@ module Geocoder::Result
|
|
|
90
111
|
end
|
|
91
112
|
end
|
|
92
113
|
end
|
|
114
|
+
|
|
115
|
+
private
|
|
116
|
+
|
|
117
|
+
def address_data
|
|
118
|
+
@data['address'] || {}
|
|
119
|
+
end
|
|
93
120
|
end
|
|
94
121
|
end
|
|
@@ -36,12 +36,13 @@ module Geocoder::Result
|
|
|
36
36
|
@data['components']['village']
|
|
37
37
|
end
|
|
38
38
|
|
|
39
|
-
|
|
40
39
|
def state
|
|
41
40
|
@data['components']['state']
|
|
42
41
|
end
|
|
43
42
|
|
|
44
|
-
|
|
43
|
+
def state_code
|
|
44
|
+
@data['components']['state_code']
|
|
45
|
+
end
|
|
45
46
|
|
|
46
47
|
def postal_code
|
|
47
48
|
@data['components']['postcode'].to_s
|
|
@@ -66,6 +67,23 @@ module Geocoder::Result
|
|
|
66
67
|
def coordinates
|
|
67
68
|
[@data['geometry']['lat'].to_f, @data['geometry']['lng'].to_f]
|
|
68
69
|
end
|
|
70
|
+
|
|
71
|
+
def viewport
|
|
72
|
+
bounds = @data['bounds'] || fail
|
|
73
|
+
south, west = %w(lat lng).map { |i| bounds['southwest'][i] }
|
|
74
|
+
north, east = %w(lat lng).map { |i| bounds['northeast'][i] }
|
|
75
|
+
[south, west, north, east]
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def time_zone
|
|
79
|
+
# The OpenCage API documentation states that `annotations` is available
|
|
80
|
+
# "when possible" https://geocoder.opencagedata.com/api#annotations
|
|
81
|
+
@data
|
|
82
|
+
.fetch('annotations', {})
|
|
83
|
+
.fetch('timezone', {})
|
|
84
|
+
.fetch('name', nil)
|
|
85
|
+
end
|
|
86
|
+
|
|
69
87
|
def self.response_attributes
|
|
70
88
|
%w[boundingbox license
|
|
71
89
|
formatted stadium]
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
require 'geocoder/results/base'
|
|
2
|
+
|
|
3
|
+
module Geocoder::Result
|
|
4
|
+
class Osmnames < Base
|
|
5
|
+
def address
|
|
6
|
+
@data['display_name']
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def coordinates
|
|
10
|
+
[@data['lat'].to_f, @data['lon'].to_f]
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def viewport
|
|
14
|
+
west, south, east, north = @data['boundingbox'].map(&:to_f)
|
|
15
|
+
[south, west, north, east]
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def state
|
|
19
|
+
@data['state']
|
|
20
|
+
end
|
|
21
|
+
alias_method :state_code, :state
|
|
22
|
+
|
|
23
|
+
def place_class
|
|
24
|
+
@data['class']
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def place_type
|
|
28
|
+
@data['type']
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def postal_code
|
|
32
|
+
''
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def country_code
|
|
36
|
+
@data['country_code']
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def country
|
|
40
|
+
@data['country']
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def self.response_attributes
|
|
44
|
+
%w[house_number street city name osm_id osm_type boundingbox place_rank
|
|
45
|
+
importance county rank name_suffix]
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
response_attributes.each do |a|
|
|
49
|
+
unless method_defined?(a)
|
|
50
|
+
define_method a do
|
|
51
|
+
@data[a]
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
require 'geocoder/results/base'
|
|
2
|
+
|
|
3
|
+
module Geocoder::Result
|
|
4
|
+
class PcMiler < Base
|
|
5
|
+
# sample response:
|
|
6
|
+
# https://singlesearch.alk.com/na/api/search?authToken=<TOKEN>&include=Meta&query=Feasterville
|
|
7
|
+
#
|
|
8
|
+
# {
|
|
9
|
+
# "Err": 0,
|
|
10
|
+
# "ErrString": "OK",
|
|
11
|
+
# "QueryConfidence": 1,
|
|
12
|
+
# "TimeInMilliseconds": 93,
|
|
13
|
+
# "GridDataVersion": "GRD_ALK.NA.2023.01.18.29.1.1",
|
|
14
|
+
# "CommitID": "pcmws-22.08.11.0-1778-g586da49bd1b: 05/30/2023 20:14",
|
|
15
|
+
# "Locations": [
|
|
16
|
+
# {
|
|
17
|
+
# "Address": {
|
|
18
|
+
# "StreetAddress": "",
|
|
19
|
+
# "LocalArea": "",
|
|
20
|
+
# "City": "Feasterville",
|
|
21
|
+
# "State": "PA",
|
|
22
|
+
# "StateName": "Pennsylvania",
|
|
23
|
+
# "Zip": "19053",
|
|
24
|
+
# "County": "Bucks",
|
|
25
|
+
# "Country": "US",
|
|
26
|
+
# "CountryFullName": "United States",
|
|
27
|
+
# "SPLC": null
|
|
28
|
+
# },
|
|
29
|
+
# "Coords": {
|
|
30
|
+
# "Lat": "40.150025",
|
|
31
|
+
# "Lon": "-75.002511"
|
|
32
|
+
# },
|
|
33
|
+
# "StreetCoords": {
|
|
34
|
+
# "Lat": "40.150098",
|
|
35
|
+
# "Lon": "-75.002827"
|
|
36
|
+
# },
|
|
37
|
+
# "Region": 4,
|
|
38
|
+
# "POITypeID": 0,
|
|
39
|
+
# "PersistentPOIID": -1,
|
|
40
|
+
# "SiteID": -1,
|
|
41
|
+
# "ResultType": 4,
|
|
42
|
+
# "ShortString": "Feasterville",
|
|
43
|
+
# "GridID": 37172748,
|
|
44
|
+
# "LinkID": 188,
|
|
45
|
+
# "Percent": 6291,
|
|
46
|
+
# "TimeZone": "GMT-4:00 EDT"
|
|
47
|
+
# }
|
|
48
|
+
# ]
|
|
49
|
+
# }
|
|
50
|
+
|
|
51
|
+
def address(format=:unused)
|
|
52
|
+
[street, city, state, postal_code, country]
|
|
53
|
+
.map { |i| i == '' ? nil : i }
|
|
54
|
+
.compact
|
|
55
|
+
.join(', ')
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def coordinates
|
|
59
|
+
coords = data["Coords"] || {}
|
|
60
|
+
[coords["Lat"].to_f, coords["Lon"].to_f]
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def street
|
|
64
|
+
address_data["StreetAddress"]
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def city
|
|
68
|
+
address_data["City"]
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def state
|
|
72
|
+
address_data["StateName"]
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def state_code
|
|
76
|
+
address_data["State"]
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def postal_code
|
|
80
|
+
address_data["Zip"]
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def country
|
|
84
|
+
address_data["CountryFullName"]
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def country_code
|
|
88
|
+
address_data["Country"]
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
private
|
|
92
|
+
|
|
93
|
+
def address_data
|
|
94
|
+
data["Address"] || {}
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
require 'geocoder/results/base'
|
|
2
|
+
|
|
3
|
+
module Geocoder::Result
|
|
4
|
+
class Pelias < Base
|
|
5
|
+
def address(format = :full)
|
|
6
|
+
properties['label']
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def city
|
|
10
|
+
locality
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def coordinates
|
|
14
|
+
geometry['coordinates'].reverse
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def country_code
|
|
18
|
+
properties['country_a']
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def postal_code
|
|
22
|
+
properties['postalcode'].to_s
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def province
|
|
26
|
+
state
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def state
|
|
30
|
+
properties['region']
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def state_code
|
|
34
|
+
properties['region_a']
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def self.response_attributes
|
|
38
|
+
%w[county confidence country gid id layer localadmin locality neighborhood]
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
response_attributes.each do |a|
|
|
42
|
+
define_method a do
|
|
43
|
+
properties[a]
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
private
|
|
48
|
+
|
|
49
|
+
def geometry
|
|
50
|
+
@data.fetch('geometry', {})
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def properties
|
|
54
|
+
@data.fetch('properties', {})
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
require 'geocoder/results/base'
|
|
2
|
+
|
|
3
|
+
module Geocoder::Result
|
|
4
|
+
class Photon < Base
|
|
5
|
+
def name
|
|
6
|
+
properties['name']
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def address(_format = :full)
|
|
10
|
+
parts = []
|
|
11
|
+
parts << name if name
|
|
12
|
+
parts << street_address if street_address
|
|
13
|
+
parts << city
|
|
14
|
+
parts << state if state
|
|
15
|
+
parts << postal_code
|
|
16
|
+
parts << country
|
|
17
|
+
|
|
18
|
+
parts.join(', ')
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def street_address
|
|
22
|
+
return unless street
|
|
23
|
+
return street unless house_number
|
|
24
|
+
|
|
25
|
+
"#{house_number} #{street}"
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def house_number
|
|
29
|
+
properties['housenumber']
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def street
|
|
33
|
+
properties['street']
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def postal_code
|
|
37
|
+
properties['postcode']
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def city
|
|
41
|
+
properties['city']
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def state
|
|
45
|
+
properties['state']
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def state_code
|
|
49
|
+
''
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def country
|
|
53
|
+
properties['country']
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def country_code
|
|
57
|
+
''
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def coordinates
|
|
61
|
+
return unless geometry
|
|
62
|
+
return unless geometry[:coordinates]
|
|
63
|
+
|
|
64
|
+
geometry[:coordinates].reverse
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def geometry
|
|
68
|
+
return unless data['geometry']
|
|
69
|
+
|
|
70
|
+
symbol_hash data['geometry']
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def bounds
|
|
74
|
+
properties['extent']
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
# Type of the result (OSM object type), one of:
|
|
78
|
+
#
|
|
79
|
+
# :node
|
|
80
|
+
# :way
|
|
81
|
+
# :relation
|
|
82
|
+
#
|
|
83
|
+
def type
|
|
84
|
+
{
|
|
85
|
+
'N' => :node,
|
|
86
|
+
'W' => :way,
|
|
87
|
+
'R' => :relation
|
|
88
|
+
}[properties['osm_type']]
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def osm_id
|
|
92
|
+
properties['osm_id']
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
# See: https://wiki.openstreetmap.org/wiki/Tags
|
|
96
|
+
def osm_tag
|
|
97
|
+
return unless properties['osm_key']
|
|
98
|
+
return properties['osm_key'] unless properties['osm_value']
|
|
99
|
+
|
|
100
|
+
"#{properties['osm_key']}=#{properties['osm_value']}"
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
private
|
|
104
|
+
|
|
105
|
+
def properties
|
|
106
|
+
@properties ||= data['properties'] || {}
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
def symbol_hash(orig_hash)
|
|
110
|
+
{}.tap do |result|
|
|
111
|
+
orig_hash.each_key do |key|
|
|
112
|
+
next unless orig_hash[key]
|
|
113
|
+
|
|
114
|
+
result[key.to_sym] = orig_hash[key]
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
end
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
require 'geocoder/results/base'
|
|
2
|
+
|
|
3
|
+
module Geocoder::Result
|
|
4
|
+
class PostcodesIo < Base
|
|
5
|
+
|
|
6
|
+
def coordinates
|
|
7
|
+
[@data['latitude'].to_f, @data['longitude'].to_f]
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def quality
|
|
11
|
+
@data['quality']
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def postal_code
|
|
15
|
+
@data['postcode']
|
|
16
|
+
end
|
|
17
|
+
alias address postal_code
|
|
18
|
+
|
|
19
|
+
def city
|
|
20
|
+
@data['admin_ward']
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def county
|
|
24
|
+
@data['admin_county']
|
|
25
|
+
end
|
|
26
|
+
alias state county
|
|
27
|
+
|
|
28
|
+
def state_code
|
|
29
|
+
@data['codes']['admin_county']
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def country
|
|
33
|
+
'United Kingdom'
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def country_code
|
|
37
|
+
'UK'
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
@@ -3,57 +3,89 @@ require 'geocoder/lookups/base'
|
|
|
3
3
|
module Geocoder::Result
|
|
4
4
|
class SmartyStreets < Base
|
|
5
5
|
def coordinates
|
|
6
|
-
%w(latitude longitude).map do |i|
|
|
6
|
+
result = %w(latitude longitude).map do |i|
|
|
7
7
|
zipcode_endpoint? ? zipcodes.first[i] : metadata[i]
|
|
8
8
|
end
|
|
9
|
+
|
|
10
|
+
if result.compact.empty?
|
|
11
|
+
nil
|
|
12
|
+
else
|
|
13
|
+
result
|
|
14
|
+
end
|
|
9
15
|
end
|
|
10
16
|
|
|
11
17
|
def address
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
18
|
+
parts =
|
|
19
|
+
if international_endpoint?
|
|
20
|
+
(1..12).map { |i| @data["address#{i}"] }
|
|
21
|
+
else
|
|
22
|
+
[
|
|
23
|
+
delivery_line_1,
|
|
24
|
+
delivery_line_2,
|
|
25
|
+
last_line
|
|
26
|
+
]
|
|
27
|
+
end
|
|
28
|
+
parts.select{ |i| i.to_s != "" }.join(" ")
|
|
17
29
|
end
|
|
18
30
|
|
|
19
31
|
def state
|
|
20
|
-
|
|
21
|
-
|
|
32
|
+
if international_endpoint?
|
|
33
|
+
components['administrative_area']
|
|
34
|
+
elsif zipcode_endpoint?
|
|
35
|
+
city_states.first['state']
|
|
36
|
+
else
|
|
22
37
|
components['state_abbreviation']
|
|
38
|
+
end
|
|
23
39
|
end
|
|
24
40
|
|
|
25
41
|
def state_code
|
|
26
|
-
|
|
27
|
-
|
|
42
|
+
if international_endpoint?
|
|
43
|
+
components['administrative_area']
|
|
44
|
+
elsif zipcode_endpoint?
|
|
45
|
+
city_states.first['state_abbreviation']
|
|
46
|
+
else
|
|
28
47
|
components['state_abbreviation']
|
|
48
|
+
end
|
|
29
49
|
end
|
|
30
50
|
|
|
31
51
|
def country
|
|
32
|
-
|
|
33
|
-
|
|
52
|
+
international_endpoint? ?
|
|
53
|
+
components['country_iso_3'] :
|
|
54
|
+
"United States"
|
|
34
55
|
end
|
|
35
56
|
|
|
36
57
|
def country_code
|
|
37
|
-
|
|
38
|
-
|
|
58
|
+
international_endpoint? ?
|
|
59
|
+
components['country_iso_3'] :
|
|
60
|
+
"US"
|
|
39
61
|
end
|
|
40
62
|
|
|
41
63
|
## Extra methods not in base.rb ------------------------
|
|
42
64
|
|
|
43
65
|
def street
|
|
44
|
-
|
|
66
|
+
international_endpoint? ?
|
|
67
|
+
components['thoroughfare_name'] :
|
|
68
|
+
components['street_name']
|
|
45
69
|
end
|
|
46
70
|
|
|
47
71
|
def city
|
|
48
|
-
|
|
49
|
-
|
|
72
|
+
if international_endpoint?
|
|
73
|
+
components['locality']
|
|
74
|
+
elsif zipcode_endpoint?
|
|
75
|
+
city_states.first['city']
|
|
76
|
+
else
|
|
50
77
|
components['city_name']
|
|
78
|
+
end
|
|
51
79
|
end
|
|
52
80
|
|
|
53
81
|
def zipcode
|
|
54
|
-
|
|
55
|
-
|
|
82
|
+
if international_endpoint?
|
|
83
|
+
components['postal_code']
|
|
84
|
+
elsif zipcode_endpoint?
|
|
85
|
+
zipcodes.first['zipcode']
|
|
86
|
+
else
|
|
56
87
|
components['zipcode']
|
|
88
|
+
end
|
|
57
89
|
end
|
|
58
90
|
alias_method :postal_code, :zipcode
|
|
59
91
|
|
|
@@ -72,6 +104,10 @@ module Geocoder::Result
|
|
|
72
104
|
zipcodes.any?
|
|
73
105
|
end
|
|
74
106
|
|
|
107
|
+
def international_endpoint?
|
|
108
|
+
!@data['address1'].nil?
|
|
109
|
+
end
|
|
110
|
+
|
|
75
111
|
[
|
|
76
112
|
:delivery_line_1,
|
|
77
113
|
:delivery_line_2,
|
|
@@ -3,11 +3,6 @@ require 'geocoder/results/base'
|
|
|
3
3
|
module Geocoder::Result
|
|
4
4
|
class Telize < Base
|
|
5
5
|
|
|
6
|
-
def address(format = :full)
|
|
7
|
-
s = state_code.to_s == "" ? "" : ", #{state_code}"
|
|
8
|
-
"#{city}#{s} #{postal_code}, #{country}".sub(/^[ ,]*/, "")
|
|
9
|
-
end
|
|
10
|
-
|
|
11
6
|
def city
|
|
12
7
|
@data['city']
|
|
13
8
|
end
|