ultra-fast-mod 0.0.1
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 +7 -0
- data/geocoder-1.8.6/CHANGELOG.md +669 -0
- data/geocoder-1.8.6/LICENSE +20 -0
- data/geocoder-1.8.6/README.md +827 -0
- data/geocoder-1.8.6/bin/console +13 -0
- data/geocoder-1.8.6/bin/geocode +5 -0
- data/geocoder-1.8.6/examples/app_defined_lookup_services.rb +22 -0
- data/geocoder-1.8.6/examples/cache_bypass.rb +48 -0
- data/geocoder-1.8.6/examples/reverse_geocode_job.rb +40 -0
- data/geocoder-1.8.6/lib/easting_northing.rb +171 -0
- data/geocoder-1.8.6/lib/generators/geocoder/config/config_generator.rb +14 -0
- data/geocoder-1.8.6/lib/generators/geocoder/config/templates/initializer.rb +27 -0
- data/geocoder-1.8.6/lib/generators/geocoder/maxmind/geolite_city_generator.rb +30 -0
- data/geocoder-1.8.6/lib/generators/geocoder/maxmind/geolite_country_generator.rb +30 -0
- data/geocoder-1.8.6/lib/generators/geocoder/maxmind/templates/migration/geolite_city.rb +30 -0
- data/geocoder-1.8.6/lib/generators/geocoder/maxmind/templates/migration/geolite_country.rb +17 -0
- data/geocoder-1.8.6/lib/generators/geocoder/migration_version.rb +15 -0
- data/geocoder-1.8.6/lib/geocoder/cache.rb +77 -0
- data/geocoder-1.8.6/lib/geocoder/cache_stores/base.rb +40 -0
- data/geocoder-1.8.6/lib/geocoder/cache_stores/generic.rb +35 -0
- data/geocoder-1.8.6/lib/geocoder/cache_stores/redis.rb +34 -0
- data/geocoder-1.8.6/lib/geocoder/calculations.rb +420 -0
- data/geocoder-1.8.6/lib/geocoder/cli.rb +121 -0
- data/geocoder-1.8.6/lib/geocoder/configuration.rb +151 -0
- data/geocoder-1.8.6/lib/geocoder/configuration_hash.rb +11 -0
- data/geocoder-1.8.6/lib/geocoder/esri_token.rb +38 -0
- data/geocoder-1.8.6/lib/geocoder/exceptions.rb +40 -0
- data/geocoder-1.8.6/lib/geocoder/ip_address.rb +36 -0
- data/geocoder-1.8.6/lib/geocoder/kernel_logger.rb +25 -0
- data/geocoder-1.8.6/lib/geocoder/logger.rb +47 -0
- data/geocoder-1.8.6/lib/geocoder/lookup.rb +155 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/abstract_api.rb +46 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/amap.rb +63 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/amazon_location_service.rb +58 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/azure.rb +56 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/baidu.rb +63 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/baidu_ip.rb +30 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/ban_data_gouv_fr.rb +143 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/base.rb +351 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/bing.rb +82 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/db_ip_com.rb +52 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/esri.rb +114 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/freegeoip.rb +62 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/geoapify.rb +78 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/geocoder_ca.rb +53 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/geocodio.rb +42 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/geoip2.rb +49 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/geoportail_lu.rb +65 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/google.rb +100 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/google_places_details.rb +64 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/google_places_search.rb +75 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/google_premier.rb +61 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/here.rb +73 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/ip2location.rb +71 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/ip2location_io.rb +62 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/ip2location_lite.rb +40 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/ipapi_com.rb +82 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/ipbase.rb +49 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/ipdata_co.rb +62 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/ipgeolocation.rb +51 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/ipinfo_io.rb +44 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/ipinfo_io_lite.rb +42 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/ipqualityscore.rb +50 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/ipregistry.rb +68 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/ipstack.rb +63 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/latlon.rb +58 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/location_iq.rb +54 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/mapbox.rb +60 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/mapquest.rb +58 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/maxmind.rb +90 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/maxmind_geoip2.rb +70 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/maxmind_local.rb +71 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/melissa_street.rb +41 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/nationaal_georegister_nl.rb +38 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/nominatim.rb +64 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/opencagedata.rb +65 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/osmnames.rb +57 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/pc_miler.rb +87 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/pdok_nl.rb +43 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/pelias.rb +63 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/photon.rb +89 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/pickpoint.rb +41 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/pointpin.rb +69 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/postcode_anywhere_uk.rb +50 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/postcodes_io.rb +31 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/smarty_streets.rb +68 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/telize.rb +75 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/tencent.rb +59 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/test.rb +49 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/twogis.rb +58 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/uk_ordnance_survey_names.rb +59 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/yandex.rb +61 -0
- data/geocoder-1.8.6/lib/geocoder/models/active_record.rb +51 -0
- data/geocoder-1.8.6/lib/geocoder/models/base.rb +39 -0
- data/geocoder-1.8.6/lib/geocoder/models/mongo_base.rb +62 -0
- data/geocoder-1.8.6/lib/geocoder/models/mongo_mapper.rb +26 -0
- data/geocoder-1.8.6/lib/geocoder/models/mongoid.rb +32 -0
- data/geocoder-1.8.6/lib/geocoder/query.rb +125 -0
- data/geocoder-1.8.6/lib/geocoder/railtie.rb +26 -0
- data/geocoder-1.8.6/lib/geocoder/request.rb +114 -0
- data/geocoder-1.8.6/lib/geocoder/results/abstract_api.rb +146 -0
- data/geocoder-1.8.6/lib/geocoder/results/amap.rb +87 -0
- data/geocoder-1.8.6/lib/geocoder/results/amazon_location_service.rb +62 -0
- data/geocoder-1.8.6/lib/geocoder/results/azure.rb +65 -0
- data/geocoder-1.8.6/lib/geocoder/results/baidu.rb +75 -0
- data/geocoder-1.8.6/lib/geocoder/results/baidu_ip.rb +62 -0
- data/geocoder-1.8.6/lib/geocoder/results/ban_data_gouv_fr.rb +282 -0
- data/geocoder-1.8.6/lib/geocoder/results/base.rb +79 -0
- data/geocoder-1.8.6/lib/geocoder/results/bing.rb +52 -0
- data/geocoder-1.8.6/lib/geocoder/results/db_ip_com.rb +58 -0
- data/geocoder-1.8.6/lib/geocoder/results/esri.rb +78 -0
- data/geocoder-1.8.6/lib/geocoder/results/freegeoip.rb +40 -0
- data/geocoder-1.8.6/lib/geocoder/results/geoapify.rb +179 -0
- data/geocoder-1.8.6/lib/geocoder/results/geocoder_ca.rb +60 -0
- data/geocoder-1.8.6/lib/geocoder/results/geocodio.rb +78 -0
- data/geocoder-1.8.6/lib/geocoder/results/geoip2.rb +76 -0
- data/geocoder-1.8.6/lib/geocoder/results/geoportail_lu.rb +71 -0
- data/geocoder-1.8.6/lib/geocoder/results/google.rb +150 -0
- data/geocoder-1.8.6/lib/geocoder/results/google_places_details.rb +39 -0
- data/geocoder-1.8.6/lib/geocoder/results/google_places_search.rb +52 -0
- data/geocoder-1.8.6/lib/geocoder/results/google_premier.rb +6 -0
- data/geocoder-1.8.6/lib/geocoder/results/here.rb +77 -0
- data/geocoder-1.8.6/lib/geocoder/results/ip2location.rb +22 -0
- data/geocoder-1.8.6/lib/geocoder/results/ip2location_io.rb +21 -0
- data/geocoder-1.8.6/lib/geocoder/results/ip2location_lite.rb +47 -0
- data/geocoder-1.8.6/lib/geocoder/results/ipapi_com.rb +45 -0
- data/geocoder-1.8.6/lib/geocoder/results/ipbase.rb +40 -0
- data/geocoder-1.8.6/lib/geocoder/results/ipdata_co.rb +40 -0
- data/geocoder-1.8.6/lib/geocoder/results/ipgeolocation.rb +59 -0
- data/geocoder-1.8.6/lib/geocoder/results/ipinfo_io.rb +48 -0
- data/geocoder-1.8.6/lib/geocoder/results/ipinfo_io_lite.rb +16 -0
- data/geocoder-1.8.6/lib/geocoder/results/ipqualityscore.rb +54 -0
- data/geocoder-1.8.6/lib/geocoder/results/ipregistry.rb +304 -0
- data/geocoder-1.8.6/lib/geocoder/results/ipstack.rb +60 -0
- data/geocoder-1.8.6/lib/geocoder/results/latlon.rb +71 -0
- data/geocoder-1.8.6/lib/geocoder/results/location_iq.rb +6 -0
- data/geocoder-1.8.6/lib/geocoder/results/mapbox.rb +80 -0
- data/geocoder-1.8.6/lib/geocoder/results/mapquest.rb +48 -0
- data/geocoder-1.8.6/lib/geocoder/results/maxmind.rb +130 -0
- data/geocoder-1.8.6/lib/geocoder/results/maxmind_geoip2.rb +9 -0
- data/geocoder-1.8.6/lib/geocoder/results/maxmind_local.rb +44 -0
- data/geocoder-1.8.6/lib/geocoder/results/melissa_street.rb +46 -0
- data/geocoder-1.8.6/lib/geocoder/results/nationaal_georegister_nl.rb +62 -0
- data/geocoder-1.8.6/lib/geocoder/results/nominatim.rb +121 -0
- data/geocoder-1.8.6/lib/geocoder/results/opencagedata.rb +100 -0
- data/geocoder-1.8.6/lib/geocoder/results/osmnames.rb +56 -0
- data/geocoder-1.8.6/lib/geocoder/results/pc_miler.rb +98 -0
- data/geocoder-1.8.6/lib/geocoder/results/pdok_nl.rb +62 -0
- data/geocoder-1.8.6/lib/geocoder/results/pelias.rb +58 -0
- data/geocoder-1.8.6/lib/geocoder/results/photon.rb +119 -0
- data/geocoder-1.8.6/lib/geocoder/results/pickpoint.rb +6 -0
- data/geocoder-1.8.6/lib/geocoder/results/pointpin.rb +40 -0
- data/geocoder-1.8.6/lib/geocoder/results/postcode_anywhere_uk.rb +42 -0
- data/geocoder-1.8.6/lib/geocoder/results/postcodes_io.rb +40 -0
- data/geocoder-1.8.6/lib/geocoder/results/smarty_streets.rb +142 -0
- data/geocoder-1.8.6/lib/geocoder/results/telize.rb +40 -0
- data/geocoder-1.8.6/lib/geocoder/results/tencent.rb +72 -0
- data/geocoder-1.8.6/lib/geocoder/results/test.rb +33 -0
- data/geocoder-1.8.6/lib/geocoder/results/twogis.rb +76 -0
- data/geocoder-1.8.6/lib/geocoder/results/uk_ordnance_survey_names.rb +59 -0
- data/geocoder-1.8.6/lib/geocoder/results/yandex.rb +292 -0
- data/geocoder-1.8.6/lib/geocoder/sql.rb +110 -0
- data/geocoder-1.8.6/lib/geocoder/stores/active_record.rb +329 -0
- data/geocoder-1.8.6/lib/geocoder/stores/base.rb +115 -0
- data/geocoder-1.8.6/lib/geocoder/stores/mongo_base.rb +58 -0
- data/geocoder-1.8.6/lib/geocoder/stores/mongo_mapper.rb +13 -0
- data/geocoder-1.8.6/lib/geocoder/stores/mongoid.rb +13 -0
- data/geocoder-1.8.6/lib/geocoder/util.rb +29 -0
- data/geocoder-1.8.6/lib/geocoder/version.rb +3 -0
- data/geocoder-1.8.6/lib/geocoder.rb +48 -0
- data/geocoder-1.8.6/lib/maxmind_database.rb +109 -0
- data/geocoder-1.8.6/lib/tasks/geocoder.rake +54 -0
- data/geocoder-1.8.6/lib/tasks/maxmind.rake +73 -0
- data/ultra-fast-mod.gemspec +12 -0
- metadata +214 -0
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
require 'geocoder/results/base'
|
|
2
|
+
|
|
3
|
+
module Geocoder::Result
|
|
4
|
+
class Yandex < Base
|
|
5
|
+
# Yandex result has difficult tree structure,
|
|
6
|
+
# and presence of some nodes depends on exact search case.
|
|
7
|
+
|
|
8
|
+
# Also Yandex lacks documentation about it.
|
|
9
|
+
# See https://tech.yandex.com/maps/doc/geocoder/desc/concepts/response_structure-docpage/
|
|
10
|
+
|
|
11
|
+
# Ultimatly, we need to find Locality and/or Thoroughfare data.
|
|
12
|
+
|
|
13
|
+
# It may resides on the top (ADDRESS_DETAILS) level.
|
|
14
|
+
# example: 'Baltic Sea'
|
|
15
|
+
# "AddressDetails": {
|
|
16
|
+
# "Locality": {
|
|
17
|
+
# "Premise": {
|
|
18
|
+
# "PremiseName": "Baltic Sea"
|
|
19
|
+
# }
|
|
20
|
+
# }
|
|
21
|
+
# }
|
|
22
|
+
|
|
23
|
+
ADDRESS_DETAILS = %w[
|
|
24
|
+
GeoObject metaDataProperty GeocoderMetaData
|
|
25
|
+
AddressDetails
|
|
26
|
+
].freeze
|
|
27
|
+
|
|
28
|
+
# On COUNTRY_LEVEL.
|
|
29
|
+
# example: 'Potomak'
|
|
30
|
+
# "AddressDetails": {
|
|
31
|
+
# "Country": {
|
|
32
|
+
# "AddressLine": "reka Potomak",
|
|
33
|
+
# "CountryNameCode": "US",
|
|
34
|
+
# "CountryName": "United States of America",
|
|
35
|
+
# "Locality": {
|
|
36
|
+
# "Premise": {
|
|
37
|
+
# "PremiseName": "reka Potomak"
|
|
38
|
+
# }
|
|
39
|
+
# }
|
|
40
|
+
# }
|
|
41
|
+
# }
|
|
42
|
+
|
|
43
|
+
COUNTRY_LEVEL = %w[
|
|
44
|
+
GeoObject metaDataProperty GeocoderMetaData
|
|
45
|
+
AddressDetails Country
|
|
46
|
+
].freeze
|
|
47
|
+
|
|
48
|
+
# On ADMIN_LEVEL (usually state or city)
|
|
49
|
+
# example: 'Moscow, Tverskaya'
|
|
50
|
+
# "AddressDetails": {
|
|
51
|
+
# "Country": {
|
|
52
|
+
# "AddressLine": "Moscow, Tverskaya Street",
|
|
53
|
+
# "CountryNameCode": "RU",
|
|
54
|
+
# "CountryName": "Russia",
|
|
55
|
+
# "AdministrativeArea": {
|
|
56
|
+
# "AdministrativeAreaName": "Moscow",
|
|
57
|
+
# "Locality": {
|
|
58
|
+
# "LocalityName": "Moscow",
|
|
59
|
+
# "Thoroughfare": {
|
|
60
|
+
# "ThoroughfareName": "Tverskaya Street"
|
|
61
|
+
# }
|
|
62
|
+
# }
|
|
63
|
+
# }
|
|
64
|
+
# }
|
|
65
|
+
# }
|
|
66
|
+
|
|
67
|
+
ADMIN_LEVEL = %w[
|
|
68
|
+
GeoObject metaDataProperty GeocoderMetaData
|
|
69
|
+
AddressDetails Country
|
|
70
|
+
AdministrativeArea
|
|
71
|
+
].freeze
|
|
72
|
+
|
|
73
|
+
# On SUBADMIN_LEVEL (may refer to urban district)
|
|
74
|
+
# example: 'Moscow Region, Krasnogorsk'
|
|
75
|
+
# "AddressDetails": {
|
|
76
|
+
# "Country": {
|
|
77
|
+
# "AddressLine": "Moscow Region, Krasnogorsk",
|
|
78
|
+
# "CountryNameCode": "RU",
|
|
79
|
+
# "CountryName": "Russia",
|
|
80
|
+
# "AdministrativeArea": {
|
|
81
|
+
# "AdministrativeAreaName": "Moscow Region",
|
|
82
|
+
# "SubAdministrativeArea": {
|
|
83
|
+
# "SubAdministrativeAreaName": "gorodskoy okrug Krasnogorsk",
|
|
84
|
+
# "Locality": {
|
|
85
|
+
# "LocalityName": "Krasnogorsk"
|
|
86
|
+
# }
|
|
87
|
+
# }
|
|
88
|
+
# }
|
|
89
|
+
# }
|
|
90
|
+
# }
|
|
91
|
+
|
|
92
|
+
SUBADMIN_LEVEL = %w[
|
|
93
|
+
GeoObject metaDataProperty GeocoderMetaData
|
|
94
|
+
AddressDetails Country
|
|
95
|
+
AdministrativeArea
|
|
96
|
+
SubAdministrativeArea
|
|
97
|
+
].freeze
|
|
98
|
+
|
|
99
|
+
# On DEPENDENT_LOCALITY_1 (may refer to district of city)
|
|
100
|
+
# example: 'Paris, Etienne Marcel'
|
|
101
|
+
# "AddressDetails": {
|
|
102
|
+
# "Country": {
|
|
103
|
+
# "AddressLine": "Île-de-France, Paris, 1er Arrondissement, Rue Étienne Marcel",
|
|
104
|
+
# "CountryNameCode": "FR",
|
|
105
|
+
# "CountryName": "France",
|
|
106
|
+
# "AdministrativeArea": {
|
|
107
|
+
# "AdministrativeAreaName": "Île-de-France",
|
|
108
|
+
# "Locality": {
|
|
109
|
+
# "LocalityName": "Paris",
|
|
110
|
+
# "DependentLocality": {
|
|
111
|
+
# "DependentLocalityName": "1er Arrondissement",
|
|
112
|
+
# "Thoroughfare": {
|
|
113
|
+
# "ThoroughfareName": "Rue Étienne Marcel"
|
|
114
|
+
# }
|
|
115
|
+
# }
|
|
116
|
+
# }
|
|
117
|
+
# }
|
|
118
|
+
# }
|
|
119
|
+
# }
|
|
120
|
+
|
|
121
|
+
DEPENDENT_LOCALITY_1 = %w[
|
|
122
|
+
GeoObject metaDataProperty GeocoderMetaData
|
|
123
|
+
AddressDetails Country
|
|
124
|
+
AdministrativeArea Locality
|
|
125
|
+
DependentLocality
|
|
126
|
+
].freeze
|
|
127
|
+
|
|
128
|
+
# On DEPENDENT_LOCALITY_2 (for special cases like turkish "mahalle")
|
|
129
|
+
# https://en.wikipedia.org/wiki/Mahalle
|
|
130
|
+
# example: 'Istanbul Mabeyinci Yokuşu 17'
|
|
131
|
+
|
|
132
|
+
# "AddressDetails": {
|
|
133
|
+
# "Country": {
|
|
134
|
+
# "AddressLine": "İstanbul, Fatih, Saraç İshak Mah., Mabeyinci Yokuşu, 17",
|
|
135
|
+
# "CountryNameCode": "TR",
|
|
136
|
+
# "CountryName": "Turkey",
|
|
137
|
+
# "AdministrativeArea": {
|
|
138
|
+
# "AdministrativeAreaName": "İstanbul",
|
|
139
|
+
# "SubAdministrativeArea": {
|
|
140
|
+
# "SubAdministrativeAreaName": "Fatih",
|
|
141
|
+
# "Locality": {
|
|
142
|
+
# "DependentLocality": {
|
|
143
|
+
# "DependentLocalityName": "Saraç İshak Mah.",
|
|
144
|
+
# "Thoroughfare": {
|
|
145
|
+
# "ThoroughfareName": "Mabeyinci Yokuşu",
|
|
146
|
+
# "Premise": {
|
|
147
|
+
# "PremiseNumber": "17"
|
|
148
|
+
# }
|
|
149
|
+
# }
|
|
150
|
+
# }
|
|
151
|
+
# }
|
|
152
|
+
# }
|
|
153
|
+
# }
|
|
154
|
+
# }
|
|
155
|
+
# }
|
|
156
|
+
|
|
157
|
+
DEPENDENT_LOCALITY_2 = %w[
|
|
158
|
+
GeoObject metaDataProperty GeocoderMetaData
|
|
159
|
+
AddressDetails Country
|
|
160
|
+
AdministrativeArea
|
|
161
|
+
SubAdministrativeArea Locality
|
|
162
|
+
DependentLocality
|
|
163
|
+
].freeze
|
|
164
|
+
|
|
165
|
+
def coordinates
|
|
166
|
+
@data['GeoObject']['Point']['pos'].split(' ').reverse.map(&:to_f)
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
def address(_format = :full)
|
|
170
|
+
@data['GeoObject']['metaDataProperty']['GeocoderMetaData']['text']
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
def city
|
|
174
|
+
result =
|
|
175
|
+
if state.empty?
|
|
176
|
+
find_in_hash(@data, *COUNTRY_LEVEL, 'Locality', 'LocalityName')
|
|
177
|
+
elsif sub_state.empty?
|
|
178
|
+
find_in_hash(@data, *ADMIN_LEVEL, 'Locality', 'LocalityName')
|
|
179
|
+
else
|
|
180
|
+
find_in_hash(@data, *SUBADMIN_LEVEL, 'Locality', 'LocalityName')
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
result || ""
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
def country
|
|
187
|
+
find_in_hash(@data, *COUNTRY_LEVEL, 'CountryName') || ""
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
def country_code
|
|
191
|
+
find_in_hash(@data, *COUNTRY_LEVEL, 'CountryNameCode') || ""
|
|
192
|
+
end
|
|
193
|
+
|
|
194
|
+
def state
|
|
195
|
+
find_in_hash(@data, *ADMIN_LEVEL, 'AdministrativeAreaName') || ""
|
|
196
|
+
end
|
|
197
|
+
|
|
198
|
+
def sub_state
|
|
199
|
+
return "" if state.empty?
|
|
200
|
+
find_in_hash(@data, *SUBADMIN_LEVEL, 'SubAdministrativeAreaName') || ""
|
|
201
|
+
end
|
|
202
|
+
|
|
203
|
+
def state_code
|
|
204
|
+
""
|
|
205
|
+
end
|
|
206
|
+
|
|
207
|
+
def street
|
|
208
|
+
thoroughfare_data.is_a?(Hash) ? thoroughfare_data['ThoroughfareName'] : ""
|
|
209
|
+
end
|
|
210
|
+
|
|
211
|
+
def street_number
|
|
212
|
+
premise.is_a?(Hash) ? premise.fetch('PremiseNumber', "") : ""
|
|
213
|
+
end
|
|
214
|
+
|
|
215
|
+
def premise_name
|
|
216
|
+
premise.is_a?(Hash) ? premise.fetch('PremiseName', "") : ""
|
|
217
|
+
end
|
|
218
|
+
|
|
219
|
+
def postal_code
|
|
220
|
+
return "" unless premise.is_a?(Hash)
|
|
221
|
+
find_in_hash(premise, 'PostalCode', 'PostalCodeNumber') || ""
|
|
222
|
+
end
|
|
223
|
+
|
|
224
|
+
def kind
|
|
225
|
+
@data['GeoObject']['metaDataProperty']['GeocoderMetaData']['kind']
|
|
226
|
+
end
|
|
227
|
+
|
|
228
|
+
def precision
|
|
229
|
+
@data['GeoObject']['metaDataProperty']['GeocoderMetaData']['precision']
|
|
230
|
+
end
|
|
231
|
+
|
|
232
|
+
def viewport
|
|
233
|
+
envelope = @data['GeoObject']['boundedBy']['Envelope'] || fail
|
|
234
|
+
east, north = envelope['upperCorner'].split(' ').map(&:to_f)
|
|
235
|
+
west, south = envelope['lowerCorner'].split(' ').map(&:to_f)
|
|
236
|
+
[south, west, north, east]
|
|
237
|
+
end
|
|
238
|
+
|
|
239
|
+
private # ----------------------------------------------------------------
|
|
240
|
+
|
|
241
|
+
def top_level_locality
|
|
242
|
+
find_in_hash(@data, *ADDRESS_DETAILS, 'Locality')
|
|
243
|
+
end
|
|
244
|
+
|
|
245
|
+
def country_level_locality
|
|
246
|
+
find_in_hash(@data, *COUNTRY_LEVEL, 'Locality')
|
|
247
|
+
end
|
|
248
|
+
|
|
249
|
+
def admin_locality
|
|
250
|
+
find_in_hash(@data, *ADMIN_LEVEL, 'Locality')
|
|
251
|
+
end
|
|
252
|
+
|
|
253
|
+
def subadmin_locality
|
|
254
|
+
find_in_hash(@data, *SUBADMIN_LEVEL, 'Locality')
|
|
255
|
+
end
|
|
256
|
+
|
|
257
|
+
def dependent_locality
|
|
258
|
+
find_in_hash(@data, *DEPENDENT_LOCALITY_1) ||
|
|
259
|
+
find_in_hash(@data, *DEPENDENT_LOCALITY_2)
|
|
260
|
+
end
|
|
261
|
+
|
|
262
|
+
def locality_data
|
|
263
|
+
dependent_locality || subadmin_locality || admin_locality ||
|
|
264
|
+
country_level_locality || top_level_locality
|
|
265
|
+
end
|
|
266
|
+
|
|
267
|
+
def thoroughfare_data
|
|
268
|
+
locality_data['Thoroughfare'] if locality_data.is_a?(Hash)
|
|
269
|
+
end
|
|
270
|
+
|
|
271
|
+
def premise
|
|
272
|
+
if thoroughfare_data.is_a?(Hash)
|
|
273
|
+
thoroughfare_data['Premise']
|
|
274
|
+
elsif locality_data.is_a?(Hash)
|
|
275
|
+
locality_data['Premise']
|
|
276
|
+
end
|
|
277
|
+
end
|
|
278
|
+
|
|
279
|
+
def find_in_hash(source, *keys)
|
|
280
|
+
key = keys.shift
|
|
281
|
+
result = source[key]
|
|
282
|
+
|
|
283
|
+
if keys.empty?
|
|
284
|
+
return result
|
|
285
|
+
elsif !result.is_a?(Hash)
|
|
286
|
+
return nil
|
|
287
|
+
end
|
|
288
|
+
|
|
289
|
+
find_in_hash(result, *keys)
|
|
290
|
+
end
|
|
291
|
+
end
|
|
292
|
+
end
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
module Geocoder
|
|
2
|
+
module Sql
|
|
3
|
+
extend self
|
|
4
|
+
|
|
5
|
+
##
|
|
6
|
+
# Distance calculation for use with a database that supports POWER(),
|
|
7
|
+
# SQRT(), PI(), and trigonometric functions SIN(), COS(), ASIN(),
|
|
8
|
+
# ATAN2().
|
|
9
|
+
#
|
|
10
|
+
# Based on the excellent tutorial at:
|
|
11
|
+
# http://www.scribd.com/doc/2569355/Geo-Distance-Search-with-MySQL
|
|
12
|
+
#
|
|
13
|
+
def full_distance(latitude, longitude, lat_attr, lon_attr, options = {})
|
|
14
|
+
units = options[:units] || Geocoder.config.units
|
|
15
|
+
earth = Geocoder::Calculations.earth_radius(units)
|
|
16
|
+
|
|
17
|
+
"#{earth} * 2 * ASIN(SQRT(" +
|
|
18
|
+
"POWER(SIN((#{latitude.to_f} - #{lat_attr}) * PI() / 180 / 2), 2) + " +
|
|
19
|
+
"COS(#{latitude.to_f} * PI() / 180) * COS(#{lat_attr} * PI() / 180) * " +
|
|
20
|
+
"POWER(SIN((#{longitude.to_f} - #{lon_attr}) * PI() / 180 / 2), 2)" +
|
|
21
|
+
"))"
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
##
|
|
25
|
+
# Distance calculation for use with a database without trigonometric
|
|
26
|
+
# functions, like SQLite. Approach is to find objects within a square
|
|
27
|
+
# rather than a circle, so results are very approximate (will include
|
|
28
|
+
# objects outside the given radius).
|
|
29
|
+
#
|
|
30
|
+
# Distance and bearing calculations are *extremely inaccurate*. To be
|
|
31
|
+
# clear: this only exists to provide interface consistency. Results
|
|
32
|
+
# are not intended for use in production!
|
|
33
|
+
#
|
|
34
|
+
def approx_distance(latitude, longitude, lat_attr, lon_attr, options = {})
|
|
35
|
+
units = options[:units] || Geocoder.config.units
|
|
36
|
+
dx = Geocoder::Calculations.longitude_degree_distance(30, units)
|
|
37
|
+
dy = Geocoder::Calculations.latitude_degree_distance(units)
|
|
38
|
+
|
|
39
|
+
# sin of 45 degrees = average x or y component of vector
|
|
40
|
+
factor = Math.sin(Math::PI / 4)
|
|
41
|
+
|
|
42
|
+
"(#{dy} * ABS(#{lat_attr} - #{latitude.to_f}) * #{factor}) + " +
|
|
43
|
+
"(#{dx} * ABS(#{lon_attr} - #{longitude.to_f}) * #{factor})"
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def within_bounding_box(sw_lat, sw_lng, ne_lat, ne_lng, lat_attr, lon_attr)
|
|
47
|
+
spans = "#{lat_attr} BETWEEN #{sw_lat.to_f} AND #{ne_lat.to_f} AND "
|
|
48
|
+
# handle box that spans 180 longitude
|
|
49
|
+
if sw_lng.to_f > ne_lng.to_f
|
|
50
|
+
spans + "(#{lon_attr} BETWEEN #{sw_lng.to_f} AND 180 OR " +
|
|
51
|
+
"#{lon_attr} BETWEEN -180 AND #{ne_lng.to_f})"
|
|
52
|
+
else
|
|
53
|
+
spans + "#{lon_attr} BETWEEN #{sw_lng.to_f} AND #{ne_lng.to_f}"
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
##
|
|
58
|
+
# Fairly accurate bearing calculation. Takes a latitude, longitude,
|
|
59
|
+
# and an options hash which must include a :bearing value
|
|
60
|
+
# (:linear or :spherical).
|
|
61
|
+
#
|
|
62
|
+
# For use with a database that supports MOD() and trigonometric functions
|
|
63
|
+
# SIN(), COS(), ASIN(), ATAN2().
|
|
64
|
+
#
|
|
65
|
+
# Based on:
|
|
66
|
+
# http://www.beginningspatial.com/calculating_bearing_one_point_another
|
|
67
|
+
#
|
|
68
|
+
def full_bearing(latitude, longitude, lat_attr, lon_attr, options = {})
|
|
69
|
+
degrees_per_radian = Geocoder::Calculations::DEGREES_PER_RADIAN
|
|
70
|
+
case options[:bearing] || Geocoder.config.distances
|
|
71
|
+
when :linear
|
|
72
|
+
"MOD(CAST(" +
|
|
73
|
+
"(ATAN2( " +
|
|
74
|
+
"((#{lon_attr} - #{longitude.to_f}) / #{degrees_per_radian}), " +
|
|
75
|
+
"((#{lat_attr} - #{latitude.to_f}) / #{degrees_per_radian})" +
|
|
76
|
+
") * #{degrees_per_radian}) + 360 " +
|
|
77
|
+
"AS decimal), 360)"
|
|
78
|
+
when :spherical
|
|
79
|
+
"MOD(CAST(" +
|
|
80
|
+
"(ATAN2( " +
|
|
81
|
+
"SIN( (#{lon_attr} - #{longitude.to_f}) / #{degrees_per_radian} ) * " +
|
|
82
|
+
"COS( (#{lat_attr}) / #{degrees_per_radian} ), (" +
|
|
83
|
+
"COS( (#{latitude.to_f}) / #{degrees_per_radian} ) * SIN( (#{lat_attr}) / #{degrees_per_radian})" +
|
|
84
|
+
") - (" +
|
|
85
|
+
"SIN( (#{latitude.to_f}) / #{degrees_per_radian}) * COS((#{lat_attr}) / #{degrees_per_radian}) * " +
|
|
86
|
+
"COS( (#{lon_attr} - #{longitude.to_f}) / #{degrees_per_radian})" +
|
|
87
|
+
")" +
|
|
88
|
+
") * #{degrees_per_radian}) + 360 " +
|
|
89
|
+
"AS decimal), 360)"
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
##
|
|
94
|
+
# Totally lame bearing calculation. Basically useless except that it
|
|
95
|
+
# returns *something* in databases without trig functions.
|
|
96
|
+
#
|
|
97
|
+
def approx_bearing(latitude, longitude, lat_attr, lon_attr, options = {})
|
|
98
|
+
"CASE " +
|
|
99
|
+
"WHEN (#{lat_attr} >= #{latitude.to_f} AND " +
|
|
100
|
+
"#{lon_attr} >= #{longitude.to_f}) THEN 45.0 " +
|
|
101
|
+
"WHEN (#{lat_attr} < #{latitude.to_f} AND " +
|
|
102
|
+
"#{lon_attr} >= #{longitude.to_f}) THEN 135.0 " +
|
|
103
|
+
"WHEN (#{lat_attr} < #{latitude.to_f} AND " +
|
|
104
|
+
"#{lon_attr} < #{longitude.to_f}) THEN 225.0 " +
|
|
105
|
+
"WHEN (#{lat_attr} >= #{latitude.to_f} AND " +
|
|
106
|
+
"#{lon_attr} < #{longitude.to_f}) THEN 315.0 " +
|
|
107
|
+
"END"
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
end
|