geocoder 1.1.9 → 1.8.0
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 +309 -0
- data/LICENSE +1 -1
- data/README.md +544 -540
- 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 +30 -0
- data/lib/generators/geocoder/maxmind/geolite_country_generator.rb +30 -0
- data/lib/generators/geocoder/maxmind/templates/migration/geolite_city.rb +30 -0
- data/lib/generators/geocoder/maxmind/templates/migration/geolite_country.rb +17 -0
- data/lib/generators/geocoder/migration_version.rb +15 -0
- data/lib/geocoder/cache.rb +20 -32
- 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 +67 -36
- data/lib/geocoder/cli.rb +2 -2
- data/lib/geocoder/configuration.rb +33 -16
- 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 +33 -0
- data/lib/geocoder/kernel_logger.rb +25 -0
- data/lib/geocoder/logger.rb +47 -0
- data/lib/geocoder/lookup.rb +74 -11
- 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 +54 -0
- data/lib/geocoder/lookups/baidu.rb +24 -15
- data/lib/geocoder/lookups/baidu_ip.rb +30 -0
- data/lib/geocoder/lookups/ban_data_gouv_fr.rb +143 -0
- data/lib/geocoder/lookups/base.rb +109 -23
- data/lib/geocoder/lookups/bing.rb +45 -10
- data/lib/geocoder/lookups/db_ip_com.rb +52 -0
- data/lib/geocoder/lookups/dstk.rb +4 -2
- data/lib/geocoder/lookups/esri.rb +61 -8
- data/lib/geocoder/lookups/freegeoip.rb +25 -6
- data/lib/geocoder/lookups/geoapify.rb +72 -0
- data/lib/geocoder/lookups/geocoder_ca.rb +5 -6
- data/lib/geocoder/lookups/geocodio.rb +42 -0
- data/lib/geocoder/lookups/geoip2.rb +49 -0
- data/lib/geocoder/lookups/geoportail_lu.rb +65 -0
- data/lib/geocoder/lookups/google.rb +45 -12
- data/lib/geocoder/lookups/google_places_details.rb +64 -0
- data/lib/geocoder/lookups/google_places_search.rb +76 -0
- data/lib/geocoder/lookups/google_premier.rb +16 -2
- data/lib/geocoder/lookups/here.rb +73 -0
- data/lib/geocoder/lookups/ip2location.rb +71 -0
- data/lib/geocoder/lookups/ipapi_com.rb +82 -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 +9 -10
- data/lib/geocoder/lookups/maxmind.rb +10 -8
- data/lib/geocoder/lookups/maxmind_geoip2.rb +70 -0
- data/lib/geocoder/lookups/maxmind_local.rb +71 -0
- 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 +26 -6
- data/lib/geocoder/lookups/opencagedata.rb +65 -0
- data/lib/geocoder/lookups/osmnames.rb +57 -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 +69 -0
- data/lib/geocoder/lookups/postcode_anywhere_uk.rb +50 -0
- data/lib/geocoder/lookups/postcodes_io.rb +31 -0
- data/lib/geocoder/lookups/smarty_streets.rb +68 -0
- data/lib/geocoder/lookups/telize.rb +75 -0
- data/lib/geocoder/lookups/tencent.rb +59 -0
- data/lib/geocoder/lookups/test.rb +4 -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 +18 -11
- data/lib/geocoder/models/active_record.rb +9 -4
- data/lib/geocoder/models/base.rb +1 -4
- data/lib/geocoder/models/mongo_base.rb +6 -4
- data/lib/geocoder/query.rb +23 -5
- data/lib/geocoder/railtie.rb +2 -2
- data/lib/geocoder/request.rb +102 -11
- 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/baidu_ip.rb +62 -0
- 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 +78 -0
- data/lib/geocoder/results/geoip2.rb +76 -0
- 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 +39 -0
- data/lib/geocoder/results/google_places_search.rb +52 -0
- data/lib/geocoder/results/here.rb +77 -0
- data/lib/geocoder/results/ip2location.rb +22 -0
- data/lib/geocoder/results/ipapi_com.rb +45 -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 +44 -0
- 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 +100 -0
- data/lib/geocoder/results/osmnames.rb +56 -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 +40 -0
- data/lib/geocoder/results/postcode_anywhere_uk.rb +42 -0
- data/lib/geocoder/results/postcodes_io.rb +40 -0
- data/lib/geocoder/results/smarty_streets.rb +142 -0
- data/lib/geocoder/results/telize.rb +40 -0
- data/lib/geocoder/results/tencent.rb +72 -0
- data/lib/geocoder/results/test.rb +20 -3
- 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 +244 -32
- data/lib/geocoder/sql.rb +25 -21
- data/lib/geocoder/stores/active_record.rb +82 -26
- data/lib/geocoder/stores/base.rb +9 -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 +6 -13
- data/lib/maxmind_database.rb +109 -0
- data/lib/tasks/geocoder.rake +30 -3
- data/lib/tasks/maxmind.rake +73 -0
- metadata +115 -98
- data/.gitignore +0 -5
- data/.travis.yml +0 -27
- 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 -15
- data/lib/geocoder/lookups/geocoder_us.rb +0 -39
- data/lib/geocoder/lookups/ovi.rb +0 -62
- data/lib/geocoder/lookups/yahoo.rb +0 -86
- data/lib/geocoder/results/geocoder_us.rb +0 -39
- 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/active_record_test.rb +0 -15
- data/test/cache_test.rb +0 -35
- data/test/calculations_test.rb +0 -211
- data/test/configuration_test.rb +0 -78
- data/test/custom_block_test.rb +0 -32
- data/test/error_handling_test.rb +0 -43
- data/test/fixtures/baidu_invalid_key +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/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/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/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/ovi_madison_square_garden +0 -72
- data/test/fixtures/ovi_no_results +0 -8
- 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_invalid_key +0 -1
- data/test/fixtures/yandex_kremlin +0 -48
- data/test/fixtures/yandex_no_city_and_town +0 -112
- data/test/fixtures/yandex_no_results +0 -16
- data/test/geocoder_test.rb +0 -59
- data/test/https_test.rb +0 -16
- data/test/integration/smoke_test.rb +0 -26
- data/test/lookup_test.rb +0 -117
- data/test/method_aliases_test.rb +0 -25
- data/test/mongoid_test.rb +0 -46
- data/test/mongoid_test_helper.rb +0 -43
- data/test/near_test.rb +0 -61
- data/test/oauth_util_test.rb +0 -30
- data/test/proxy_test.rb +0 -36
- data/test/query_test.rb +0 -52
- data/test/request_test.rb +0 -29
- data/test/result_test.rb +0 -42
- data/test/services_test.rb +0 -393
- data/test/test_helper.rb +0 -289
- data/test/test_mode_test.rb +0 -59
|
@@ -2,16 +2,9 @@ require 'geocoder/results/base'
|
|
|
2
2
|
|
|
3
3
|
module Geocoder::Result
|
|
4
4
|
class Mapquest < Base
|
|
5
|
-
def latitude
|
|
6
|
-
@data["latLng"]["lat"]
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
def longitude
|
|
10
|
-
@data["latLng"]["lng"]
|
|
11
|
-
end
|
|
12
5
|
|
|
13
6
|
def coordinates
|
|
14
|
-
[
|
|
7
|
+
%w[lat lng].map{ |l| @data["latLng"][l] }
|
|
15
8
|
end
|
|
16
9
|
|
|
17
10
|
def city
|
|
@@ -26,6 +19,10 @@ module Geocoder::Result
|
|
|
26
19
|
@data['adminArea3']
|
|
27
20
|
end
|
|
28
21
|
|
|
22
|
+
def county
|
|
23
|
+
@data['adminArea4']
|
|
24
|
+
end
|
|
25
|
+
|
|
29
26
|
alias_method :state_code, :state
|
|
30
27
|
|
|
31
28
|
#FIXME: these might not be right, unclear with MQ documentation
|
|
@@ -87,11 +87,6 @@ module Geocoder::Result
|
|
|
87
87
|
[data_hash[:latitude].to_f, data_hash[:longitude].to_f]
|
|
88
88
|
end
|
|
89
89
|
|
|
90
|
-
def address(format = :full)
|
|
91
|
-
s = state_code.to_s == "" ? "" : ", #{state_code}"
|
|
92
|
-
"#{city}#{s} #{postal_code}, #{country_code}".sub(/^[ ,]*/, "")
|
|
93
|
-
end
|
|
94
|
-
|
|
95
90
|
def city
|
|
96
91
|
data_hash[:city_name]
|
|
97
92
|
end
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
require 'geocoder/results/geoip2'
|
|
2
|
+
|
|
3
|
+
module Geocoder::Result
|
|
4
|
+
class MaxmindGeoip2 < Geoip2
|
|
5
|
+
# MindmindGeoip2 has the same results as Geoip2 because both are from MaxMind's GeoIP2 Precision Services
|
|
6
|
+
# See http://dev.maxmind.com/geoip/geoip2/web-services/ The difference being that Maxmind calls the service
|
|
7
|
+
# directly while GeoIP2 uses Hive::GeoIP2. See https://github.com/desuwa/hive_geoip2
|
|
8
|
+
end
|
|
9
|
+
end
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
require 'geocoder/results/base'
|
|
2
|
+
|
|
3
|
+
module Geocoder::Result
|
|
4
|
+
class MaxmindLocal < Base
|
|
5
|
+
|
|
6
|
+
def coordinates
|
|
7
|
+
[@data[:latitude], @data[:longitude]]
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def city
|
|
11
|
+
@data[:city_name]
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def state
|
|
15
|
+
@data[:region_name]
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def state_code
|
|
19
|
+
"" # Not available in Maxmind's database
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def country
|
|
23
|
+
@data[:country_name]
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def country_code
|
|
27
|
+
@data[:country_code2]
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def postal_code
|
|
31
|
+
@data[:postal_code]
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def self.response_attributes
|
|
35
|
+
%w[ip]
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
response_attributes.each do |a|
|
|
39
|
+
define_method a do
|
|
40
|
+
@data[a]
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
require 'geocoder/results/base'
|
|
2
|
+
|
|
3
|
+
module Geocoder::Result
|
|
4
|
+
class MelissaStreet < Base
|
|
5
|
+
def address(format = :full)
|
|
6
|
+
@data['FormattedAddress']
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def street_address
|
|
10
|
+
@data['AddressLine1']
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def suffix
|
|
14
|
+
@data['ThoroughfareTrailingType']
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def number
|
|
18
|
+
@data['PremisesNumber']
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def city
|
|
22
|
+
@data['Locality']
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def state_code
|
|
26
|
+
@data['AdministrativeArea']
|
|
27
|
+
end
|
|
28
|
+
alias_method :state, :state_code
|
|
29
|
+
|
|
30
|
+
def country
|
|
31
|
+
@data['CountryName']
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def country_code
|
|
35
|
+
@data['CountryISO3166_1_Alpha2']
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def postal_code
|
|
39
|
+
@data['PostalCode']
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def coordinates
|
|
43
|
+
[@data['Latitude'].to_f, @data['Longitude'].to_f]
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
require 'geocoder/results/base'
|
|
2
|
+
|
|
3
|
+
module Geocoder::Result
|
|
4
|
+
class NationaalGeoregisterNl < Base
|
|
5
|
+
|
|
6
|
+
def response_attributes
|
|
7
|
+
@data
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def coordinates
|
|
11
|
+
@data['centroide_ll'][6..-2].split(' ').map(&:to_f).reverse
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def formatted_address
|
|
15
|
+
@data['weergavenaam']
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
alias_method :address, :formatted_address
|
|
19
|
+
|
|
20
|
+
def province
|
|
21
|
+
@data['provincienaam']
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
alias_method :state, :province
|
|
25
|
+
|
|
26
|
+
def city
|
|
27
|
+
@data['woonplaatsnaam']
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def district
|
|
31
|
+
@data['gemeentenaam']
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def street
|
|
35
|
+
@data['straatnaam']
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def street_number
|
|
39
|
+
@data['huis_nlt']
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def address_components
|
|
43
|
+
@data
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def state_code
|
|
47
|
+
@data['provinciecode']
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def postal_code
|
|
51
|
+
@data['postcode']
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def country
|
|
55
|
+
"Netherlands"
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def country_code
|
|
59
|
+
"NL"
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
@@ -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
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
require 'geocoder/results/base'
|
|
2
|
+
|
|
3
|
+
module Geocoder::Result
|
|
4
|
+
class Opencagedata < Base
|
|
5
|
+
|
|
6
|
+
def poi
|
|
7
|
+
%w[stadium bus_stop tram_stop].each do |key|
|
|
8
|
+
return @data['components'][key] if @data['components'].key?(key)
|
|
9
|
+
end
|
|
10
|
+
return nil
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def house_number
|
|
14
|
+
@data['components']['house_number']
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def address
|
|
18
|
+
@data['formatted']
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def street
|
|
22
|
+
%w[road pedestrian highway].each do |key|
|
|
23
|
+
return @data['components'][key] if @data['components'].key?(key)
|
|
24
|
+
end
|
|
25
|
+
return nil
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def city
|
|
29
|
+
%w[city town village hamlet].each do |key|
|
|
30
|
+
return @data['components'][key] if @data['components'].key?(key)
|
|
31
|
+
end
|
|
32
|
+
return nil
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def village
|
|
36
|
+
@data['components']['village']
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def state
|
|
40
|
+
@data['components']['state']
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def state_code
|
|
44
|
+
@data['components']['state_code']
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def postal_code
|
|
48
|
+
@data['components']['postcode'].to_s
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def county
|
|
52
|
+
@data['components']['county']
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def country
|
|
56
|
+
@data['components']['country']
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def country_code
|
|
60
|
+
@data['components']['country_code']
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def suburb
|
|
64
|
+
@data['components']['suburb']
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def coordinates
|
|
68
|
+
[@data['geometry']['lat'].to_f, @data['geometry']['lng'].to_f]
|
|
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
|
+
|
|
87
|
+
def self.response_attributes
|
|
88
|
+
%w[boundingbox license
|
|
89
|
+
formatted stadium]
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
response_attributes.each do |a|
|
|
93
|
+
unless method_defined?(a)
|
|
94
|
+
define_method a do
|
|
95
|
+
@data[a]
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
end
|
|
@@ -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,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 Pointpin < Base
|
|
5
|
+
|
|
6
|
+
def address
|
|
7
|
+
[ city_name, state, postal_code, country ].select{ |i| i.to_s != "" }.join(", ")
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def city
|
|
11
|
+
@data['city_name']
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def state
|
|
15
|
+
@data['region_name']
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def state_code
|
|
19
|
+
@data['region_code']
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def country
|
|
23
|
+
@data['country_name']
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def postal_code
|
|
27
|
+
@data['postcode']
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def self.response_attributes
|
|
31
|
+
%w[continent_code ip country_code country_name region_name city_name postcode latitude longitude time_zone languages]
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
response_attributes.each do |a|
|
|
35
|
+
define_method a do
|
|
36
|
+
@data[a]
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|