geocoder 1.5.1 → 1.8.5
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 +107 -0
- data/LICENSE +1 -1
- data/README.md +364 -243
- data/bin/console +13 -0
- data/examples/app_defined_lookup_services.rb +22 -0
- data/lib/easting_northing.rb +171 -0
- data/lib/generators/geocoder/config/templates/initializer.rb +6 -1
- data/lib/geocoder/cache.rb +16 -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/configuration.rb +19 -5
- data/lib/geocoder/configuration_hash.rb +4 -4
- data/lib/geocoder/ip_address.rb +11 -1
- data/lib/geocoder/lookup.rb +42 -6
- data/lib/geocoder/lookups/abstract_api.rb +46 -0
- data/lib/geocoder/lookups/amap.rb +2 -2
- data/lib/geocoder/lookups/amazon_location_service.rb +58 -0
- data/lib/geocoder/lookups/azure.rb +56 -0
- data/lib/geocoder/lookups/ban_data_gouv_fr.rb +15 -2
- data/lib/geocoder/lookups/base.rb +4 -1
- data/lib/geocoder/lookups/bing.rb +2 -2
- data/lib/geocoder/lookups/esri.rb +24 -5
- data/lib/geocoder/lookups/freegeoip.rb +12 -10
- data/lib/geocoder/lookups/geoapify.rb +78 -0
- data/lib/geocoder/lookups/geocodio.rb +1 -1
- data/lib/geocoder/lookups/geoip2.rb +4 -0
- data/lib/geocoder/lookups/geoportail_lu.rb +1 -1
- data/lib/geocoder/lookups/google.rb +7 -2
- data/lib/geocoder/lookups/google_places_details.rb +26 -12
- data/lib/geocoder/lookups/google_places_search.rb +44 -2
- data/lib/geocoder/lookups/google_premier.rb +4 -0
- data/lib/geocoder/lookups/here.rb +27 -31
- data/lib/geocoder/lookups/ip2location.rb +10 -14
- data/lib/geocoder/lookups/ip2location_io.rb +62 -0
- data/lib/geocoder/lookups/ip2location_lite.rb +40 -0
- data/lib/geocoder/lookups/ipbase.rb +49 -0
- data/lib/geocoder/lookups/ipdata_co.rb +1 -1
- data/lib/geocoder/lookups/ipgeolocation.rb +51 -0
- data/lib/geocoder/lookups/ipqualityscore.rb +50 -0
- data/lib/geocoder/lookups/ipregistry.rb +68 -0
- data/lib/geocoder/lookups/latlon.rb +1 -2
- data/lib/geocoder/lookups/location_iq.rb +5 -1
- data/lib/geocoder/lookups/mapbox.rb +3 -3
- data/lib/geocoder/lookups/maxmind_local.rb +7 -1
- data/lib/geocoder/lookups/melissa_street.rb +41 -0
- data/lib/geocoder/lookups/nationaal_georegister_nl.rb +38 -0
- data/lib/geocoder/lookups/osmnames.rb +57 -0
- data/lib/geocoder/lookups/pc_miler.rb +85 -0
- data/lib/geocoder/lookups/pdok_nl.rb +43 -0
- data/lib/geocoder/lookups/photon.rb +89 -0
- data/lib/geocoder/lookups/pickpoint.rb +1 -1
- data/lib/geocoder/lookups/smarty_streets.rb +6 -1
- data/lib/geocoder/lookups/telize.rb +1 -1
- data/lib/geocoder/lookups/tencent.rb +9 -9
- 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 +6 -7
- data/lib/geocoder/query.rb +1 -1
- data/lib/geocoder/results/abstract_api.rb +146 -0
- data/lib/geocoder/results/amazon_location_service.rb +62 -0
- data/lib/geocoder/results/azure.rb +65 -0
- data/lib/geocoder/results/baidu.rb +0 -4
- data/lib/geocoder/results/ban_data_gouv_fr.rb +28 -3
- data/lib/geocoder/results/db_ip_com.rb +1 -1
- data/lib/geocoder/results/esri.rb +5 -2
- data/lib/geocoder/results/geoapify.rb +179 -0
- data/lib/geocoder/results/here.rb +20 -22
- data/lib/geocoder/results/ip2location_io.rb +21 -0
- data/lib/geocoder/results/ip2location_lite.rb +47 -0
- data/lib/geocoder/results/ipbase.rb +40 -0
- data/lib/geocoder/results/ipgeolocation.rb +59 -0
- data/lib/geocoder/results/ipqualityscore.rb +54 -0
- data/lib/geocoder/results/ipregistry.rb +304 -0
- data/lib/geocoder/results/mapbox.rb +34 -10
- 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 +27 -15
- data/lib/geocoder/results/osmnames.rb +56 -0
- data/lib/geocoder/results/pc_miler.rb +98 -0
- data/lib/geocoder/results/pdok_nl.rb +62 -0
- data/lib/geocoder/results/photon.rb +119 -0
- 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 +217 -59
- data/lib/geocoder/sql.rb +4 -4
- data/lib/geocoder/util.rb +29 -0
- data/lib/geocoder/version.rb +1 -1
- data/lib/maxmind_database.rb +12 -12
- data/lib/tasks/maxmind.rake +1 -1
- metadata +81 -23
- data/examples/autoexpire_cache_dalli.rb +0 -62
- data/examples/autoexpire_cache_redis.rb +0 -28
- data/lib/geocoder/lookups/dstk.rb +0 -22
- data/lib/geocoder/lookups/geocoder_us.rb +0 -51
- data/lib/geocoder/results/dstk.rb +0 -6
- data/lib/geocoder/results/geocoder_us.rb +0 -39
- data/lib/hash_recursive_merge.rb +0 -74
@@ -0,0 +1,85 @@
|
|
1
|
+
require 'geocoder/lookups/base'
|
2
|
+
require "geocoder/results/pc_miler"
|
3
|
+
require 'cgi' unless defined?(CGI) && defined?(CGI.escape)
|
4
|
+
|
5
|
+
module Geocoder::Lookup
|
6
|
+
class PcMiler < Base
|
7
|
+
|
8
|
+
# https://developer.trimblemaps.com/restful-apis/location/single-search/single-search-api/#test-the-api-now
|
9
|
+
def valid_region_codes
|
10
|
+
# AF: Africa
|
11
|
+
# AS: Asia
|
12
|
+
# EU: Europe
|
13
|
+
# NA: North America
|
14
|
+
# OC: Oceania
|
15
|
+
# SA: South America
|
16
|
+
%w[AF AS EU NA OC SA]
|
17
|
+
end
|
18
|
+
|
19
|
+
def name
|
20
|
+
"PCMiler"
|
21
|
+
end
|
22
|
+
|
23
|
+
private # ---------------------------------------------------------------
|
24
|
+
|
25
|
+
def base_query_url(query)
|
26
|
+
region_code = region(query)
|
27
|
+
if !valid_region_codes.include?(region_code)
|
28
|
+
raise "region_code '#{region_code}' is invalid. use one of #{valid_region_codes}." \
|
29
|
+
"https://developer.trimblemaps.com/restful-apis/location/single-search/single-search-api/#test-the-api-now"
|
30
|
+
end
|
31
|
+
|
32
|
+
"#{protocol}://singlesearch.alk.com/#{region_code}/api/search?"
|
33
|
+
end
|
34
|
+
|
35
|
+
def results(query)
|
36
|
+
return [] unless data = fetch_data(query)
|
37
|
+
if data['Locations']
|
38
|
+
add_metadata_to_locations!(data)
|
39
|
+
data['Locations']
|
40
|
+
else
|
41
|
+
[]
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def add_metadata_to_locations!(data)
|
46
|
+
confidence = data['QueryConfidence']
|
47
|
+
data['Locations'].each do |location|
|
48
|
+
location['QueryConfidence'] = confidence
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def query_url_params(query)
|
53
|
+
if query.reverse_geocode?
|
54
|
+
lat,lon = query.coordinates
|
55
|
+
formatted_query = "#{CGI.escape(lat)},#{CGI.escape(lon)}"
|
56
|
+
else
|
57
|
+
formatted_query = query.text.to_s
|
58
|
+
end
|
59
|
+
|
60
|
+
{
|
61
|
+
authToken: configuration.api_key,
|
62
|
+
query: formatted_query,
|
63
|
+
# to add additional metadata to response such as QueryConfidence
|
64
|
+
include: 'Meta'
|
65
|
+
}.merge(super(query))
|
66
|
+
end
|
67
|
+
|
68
|
+
def region(query)
|
69
|
+
query.options[:region] || query.options['region'] || configuration[:region] || "NA"
|
70
|
+
end
|
71
|
+
|
72
|
+
def check_response_for_errors!(response)
|
73
|
+
if response.code.to_i == 403
|
74
|
+
raise_error(Geocoder::RequestDenied) ||
|
75
|
+
Geocoder.log(:warn, "Geocoding API error: 403 API key does not exist")
|
76
|
+
else
|
77
|
+
super(response)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def supported_protocols
|
82
|
+
[:https]
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'geocoder/lookups/base'
|
2
|
+
require "geocoder/results/pdok_nl"
|
3
|
+
|
4
|
+
module Geocoder::Lookup
|
5
|
+
class PdokNl < Base
|
6
|
+
|
7
|
+
def name
|
8
|
+
'pdok NL'
|
9
|
+
end
|
10
|
+
|
11
|
+
def supported_protocols
|
12
|
+
[:https]
|
13
|
+
end
|
14
|
+
|
15
|
+
private # ---------------------------------------------------------------
|
16
|
+
|
17
|
+
def cache_key(query)
|
18
|
+
base_query_url(query) + hash_to_query(query_url_params(query))
|
19
|
+
end
|
20
|
+
|
21
|
+
def base_query_url(query)
|
22
|
+
"#{protocol}://api.pdok.nl/bzk/locatieserver/search/v3_1/free?"
|
23
|
+
end
|
24
|
+
|
25
|
+
def valid_response?(response)
|
26
|
+
json = parse_json(response.body)
|
27
|
+
super(response) if json
|
28
|
+
end
|
29
|
+
|
30
|
+
def results(query)
|
31
|
+
return [] unless doc = fetch_data(query)
|
32
|
+
return doc['response']['docs']
|
33
|
+
end
|
34
|
+
|
35
|
+
def query_url_params(query)
|
36
|
+
{
|
37
|
+
fl: '*',
|
38
|
+
q: query.text,
|
39
|
+
wt: 'json'
|
40
|
+
}.merge(super)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
require 'geocoder/lookups/base'
|
2
|
+
require 'geocoder/results/photon'
|
3
|
+
|
4
|
+
module Geocoder::Lookup
|
5
|
+
class Photon < Base
|
6
|
+
def name
|
7
|
+
'Photon'
|
8
|
+
end
|
9
|
+
|
10
|
+
private # ---------------------------------------------------------------
|
11
|
+
|
12
|
+
def supported_protocols
|
13
|
+
[:http, :https]
|
14
|
+
end
|
15
|
+
|
16
|
+
def base_query_url(query)
|
17
|
+
host = configuration[:host] || 'photon.komoot.io'
|
18
|
+
method = query.reverse_geocode? ? 'reverse' : 'api'
|
19
|
+
"#{protocol}://#{host}/#{method}?"
|
20
|
+
end
|
21
|
+
|
22
|
+
def results(query)
|
23
|
+
return [] unless (doc = fetch_data(query))
|
24
|
+
return [] unless doc['type'] == 'FeatureCollection'
|
25
|
+
return [] unless doc['features'] || doc['features'].present?
|
26
|
+
|
27
|
+
doc['features']
|
28
|
+
end
|
29
|
+
|
30
|
+
def query_url_params(query)
|
31
|
+
lang = query.language || configuration.language
|
32
|
+
params = { lang: lang, limit: query.options[:limit] }
|
33
|
+
|
34
|
+
if query.reverse_geocode?
|
35
|
+
params.merge!(query_url_params_reverse(query))
|
36
|
+
else
|
37
|
+
params.merge!(query_url_params_coordinates(query))
|
38
|
+
end
|
39
|
+
|
40
|
+
params.merge!(super)
|
41
|
+
end
|
42
|
+
|
43
|
+
def query_url_params_coordinates(query)
|
44
|
+
params = { q: query.sanitized_text }
|
45
|
+
|
46
|
+
if (bias = query.options[:bias])
|
47
|
+
params.merge!(lat: bias[:latitude], lon: bias[:longitude], location_bias_scale: bias[:scale])
|
48
|
+
end
|
49
|
+
|
50
|
+
if (filter = query_url_params_coordinates_filter(query))
|
51
|
+
params.merge!(filter)
|
52
|
+
end
|
53
|
+
|
54
|
+
params
|
55
|
+
end
|
56
|
+
|
57
|
+
def query_url_params_coordinates_filter(query)
|
58
|
+
filter = query.options[:filter]
|
59
|
+
return unless filter
|
60
|
+
|
61
|
+
bbox = filter[:bbox]
|
62
|
+
{
|
63
|
+
bbox: bbox.is_a?(Array) ? bbox.join(',') : bbox,
|
64
|
+
osm_tag: filter[:osm_tag]
|
65
|
+
}
|
66
|
+
end
|
67
|
+
|
68
|
+
def query_url_params_reverse(query)
|
69
|
+
params = { lat: query.coordinates[0], lon: query.coordinates[1], radius: query.options[:radius] }
|
70
|
+
|
71
|
+
if (dsort = query.options[:distance_sort])
|
72
|
+
params[:distance_sort] = dsort ? 'true' : 'false'
|
73
|
+
end
|
74
|
+
|
75
|
+
if (filter = query_url_params_reverse_filter(query))
|
76
|
+
params.merge!(filter)
|
77
|
+
end
|
78
|
+
|
79
|
+
params
|
80
|
+
end
|
81
|
+
|
82
|
+
def query_url_params_reverse_filter(query)
|
83
|
+
filter = query.options[:filter]
|
84
|
+
return unless filter
|
85
|
+
|
86
|
+
{ query_string_filter: filter[:string] }
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
@@ -57,7 +57,12 @@ module Geocoder::Lookup
|
|
57
57
|
end
|
58
58
|
|
59
59
|
def results(query)
|
60
|
-
fetch_data(query) || []
|
60
|
+
doc = fetch_data(query) || []
|
61
|
+
if doc.is_a?(Hash) and doc.key?('status') # implies there's an error
|
62
|
+
return []
|
63
|
+
else
|
64
|
+
return doc
|
65
|
+
end
|
61
66
|
end
|
62
67
|
end
|
63
68
|
end
|
@@ -16,7 +16,7 @@ module Geocoder::Lookup
|
|
16
16
|
if configuration[:host]
|
17
17
|
"#{protocol}://#{configuration[:host]}/location/#{query.sanitized_text}"
|
18
18
|
else
|
19
|
-
"#{protocol}://telize-v1.p.
|
19
|
+
"#{protocol}://telize-v1.p.rapidapi.com/location/#{query.sanitized_text}?rapidapi-key=#{api_key}"
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
@@ -31,18 +31,18 @@ module Geocoder::Lookup
|
|
31
31
|
case doc['status']
|
32
32
|
when 0
|
33
33
|
return [doc[content_key]]
|
34
|
-
when 199
|
35
|
-
raise error(Geocoder::InvalidApiKey, "invalid api key") ||
|
36
|
-
Geocoder.log(:warn, "#{name} Geocoding API error: key is not enabled for web service usage.")
|
37
|
-
when 311
|
38
|
-
raise_error(Geocoder::RequestDenied, "request denied") ||
|
39
|
-
Geocoder.log(:warn, "#{name} Geocoding API error: request denied.")
|
40
|
-
when 310, 306
|
41
|
-
raise_error(Geocoder::InvalidRequest, "invalid request.") ||
|
42
|
-
Geocoder.log(:warn, "#{name} Geocoding API error: invalid request.")
|
43
34
|
when 311
|
44
35
|
raise_error(Geocoder::InvalidApiKey, "invalid api key") ||
|
45
36
|
Geocoder.log(:warn, "#{name} Geocoding API error: invalid api key.")
|
37
|
+
when 310
|
38
|
+
raise_error(Geocoder::InvalidRequest, "invalid request.") ||
|
39
|
+
Geocoder.log(:warn, "#{name} Geocoding API error: invalid request, invalid parameters.")
|
40
|
+
when 306
|
41
|
+
raise_error(Geocoder::InvalidRequest, "invalid request.") ||
|
42
|
+
Geocoder.log(:warn, "#{name} Geocoding API error: invalid request, check response for more info.")
|
43
|
+
when 110
|
44
|
+
raise_error(Geocoder::RequestDenied, "request denied.") ||
|
45
|
+
Geocoder.log(:warn, "#{name} Geocoding API error: request source is not authorized.")
|
46
46
|
end
|
47
47
|
return []
|
48
48
|
end
|
@@ -18,6 +18,7 @@ module Geocoder
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def self.read_stub(query_text)
|
21
|
+
@default_stub ||= nil
|
21
22
|
stubs.fetch(query_text) {
|
22
23
|
return @default_stub unless @default_stub.nil?
|
23
24
|
raise ArgumentError, "unknown stub request #{query_text}"
|
@@ -28,6 +29,10 @@ module Geocoder
|
|
28
29
|
@stubs ||= {}
|
29
30
|
end
|
30
31
|
|
32
|
+
def self.delete_stub(query_text)
|
33
|
+
stubs.delete(query_text)
|
34
|
+
end
|
35
|
+
|
31
36
|
def self.reset
|
32
37
|
@stubs = {}
|
33
38
|
@default_stub = nil
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'geocoder/lookups/base'
|
2
|
+
require "geocoder/results/twogis"
|
3
|
+
|
4
|
+
module Geocoder::Lookup
|
5
|
+
class Twogis < Base
|
6
|
+
|
7
|
+
def name
|
8
|
+
"2gis"
|
9
|
+
end
|
10
|
+
|
11
|
+
def required_api_key_parts
|
12
|
+
["key"]
|
13
|
+
end
|
14
|
+
|
15
|
+
def map_link_url(coordinates)
|
16
|
+
"https://2gis.ru/?m=#{coordinates.join(',')}"
|
17
|
+
end
|
18
|
+
|
19
|
+
def supported_protocols
|
20
|
+
[:https]
|
21
|
+
end
|
22
|
+
|
23
|
+
private # ---------------------------------------------------------------
|
24
|
+
|
25
|
+
def base_query_url(query)
|
26
|
+
"#{protocol}://catalog.api.2gis.com/3.0/items/geocode?"
|
27
|
+
end
|
28
|
+
|
29
|
+
def results(query)
|
30
|
+
return [] unless doc = fetch_data(query)
|
31
|
+
if doc['meta'] && doc['meta']['error']
|
32
|
+
Geocoder.log(:warn, "2gis Geocoding API error: #{doc['meta']["code"]} (#{doc['meta']['error']["message"]}).")
|
33
|
+
return []
|
34
|
+
end
|
35
|
+
if doc['result'] && doc = doc['result']['items']
|
36
|
+
return doc.to_a
|
37
|
+
else
|
38
|
+
Geocoder.log(:warn, "2gis Geocoding API error: unexpected response format.")
|
39
|
+
return []
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def query_url_params(query)
|
44
|
+
if query.reverse_geocode?
|
45
|
+
q = query.coordinates.reverse.join(",")
|
46
|
+
else
|
47
|
+
q = query.sanitized_text
|
48
|
+
end
|
49
|
+
params = {
|
50
|
+
:q => q,
|
51
|
+
:lang => "#{query.language || configuration.language}",
|
52
|
+
:key => configuration.api_key,
|
53
|
+
:fields => 'items.street,items.adm_div,items.full_address_name,items.point,items.geometry.centroid'
|
54
|
+
}
|
55
|
+
params.merge(super)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'geocoder/lookups/base'
|
2
|
+
require 'geocoder/results/uk_ordnance_survey_names'
|
3
|
+
|
4
|
+
module Geocoder::Lookup
|
5
|
+
class UkOrdnanceSurveyNames < Base
|
6
|
+
|
7
|
+
def name
|
8
|
+
'Ordance Survey Names'
|
9
|
+
end
|
10
|
+
|
11
|
+
def supported_protocols
|
12
|
+
[:https]
|
13
|
+
end
|
14
|
+
|
15
|
+
def base_query_url(query)
|
16
|
+
"#{protocol}://api.os.uk/search/names/v1/find?"
|
17
|
+
end
|
18
|
+
|
19
|
+
def required_api_key_parts
|
20
|
+
["key"]
|
21
|
+
end
|
22
|
+
|
23
|
+
def query_url(query)
|
24
|
+
base_query_url(query) + url_query_string(query)
|
25
|
+
end
|
26
|
+
|
27
|
+
private # -------------------------------------------------------------
|
28
|
+
|
29
|
+
def results(query)
|
30
|
+
return [] unless doc = fetch_data(query)
|
31
|
+
return [] if doc['header']['totalresults'].zero?
|
32
|
+
return doc['results'].map { |r| r['GAZETTEER_ENTRY'] }
|
33
|
+
end
|
34
|
+
|
35
|
+
def query_url_params(query)
|
36
|
+
{
|
37
|
+
query: query.sanitized_text,
|
38
|
+
key: configuration.api_key,
|
39
|
+
fq: filter
|
40
|
+
}.merge(super)
|
41
|
+
end
|
42
|
+
|
43
|
+
def local_types
|
44
|
+
%w[
|
45
|
+
City
|
46
|
+
Hamlet
|
47
|
+
Other_Settlement
|
48
|
+
Town
|
49
|
+
Village
|
50
|
+
Postcode
|
51
|
+
]
|
52
|
+
end
|
53
|
+
|
54
|
+
def filter
|
55
|
+
local_types.map { |t| "local_type:#{t}" }.join(' ')
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
end
|
@@ -24,17 +24,16 @@ module Geocoder::Lookup
|
|
24
24
|
|
25
25
|
def results(query)
|
26
26
|
return [] unless doc = fetch_data(query)
|
27
|
-
if
|
28
|
-
if
|
27
|
+
if [400, 403].include? doc['statusCode']
|
28
|
+
if doc['statusCode'] == 403 and doc['message'] == 'Invalid key'
|
29
29
|
raise_error(Geocoder::InvalidApiKey) || Geocoder.log(:warn, "Invalid API key.")
|
30
30
|
else
|
31
|
-
Geocoder.log(:warn, "Yandex Geocoding API error: #{
|
31
|
+
Geocoder.log(:warn, "Yandex Geocoding API error: #{doc['statusCode']} (#{doc['message']}).")
|
32
32
|
end
|
33
33
|
return []
|
34
34
|
end
|
35
35
|
if doc = doc['response']['GeoObjectCollection']
|
36
|
-
|
37
|
-
return meta['found'].to_i > 0 ? doc['featureMember'] : []
|
36
|
+
return doc['featureMember'].to_a
|
38
37
|
else
|
39
38
|
Geocoder.log(:warn, "Yandex Geocoding API error: unexpected response format.")
|
40
39
|
return []
|
@@ -50,8 +49,8 @@ module Geocoder::Lookup
|
|
50
49
|
params = {
|
51
50
|
:geocode => q,
|
52
51
|
:format => "json",
|
53
|
-
:
|
54
|
-
:
|
52
|
+
:lang => "#{query.language || configuration.language}", # supports ru, uk, be, default -> ru
|
53
|
+
:apikey => configuration.api_key
|
55
54
|
}
|
56
55
|
unless (bounds = query.options[:bounds]).nil?
|
57
56
|
params[:bbox] = bounds.map{ |point| "%f,%f" % point }.join('~')
|
data/lib/geocoder/query.rb
CHANGED
@@ -0,0 +1,146 @@
|
|
1
|
+
require 'geocoder/results/base'
|
2
|
+
|
3
|
+
module Geocoder
|
4
|
+
module Result
|
5
|
+
class AbstractApi < Base
|
6
|
+
|
7
|
+
##
|
8
|
+
# Geolocation
|
9
|
+
|
10
|
+
def state
|
11
|
+
@data['region']
|
12
|
+
end
|
13
|
+
|
14
|
+
def state_code
|
15
|
+
@data['region_iso_code']
|
16
|
+
end
|
17
|
+
|
18
|
+
def city
|
19
|
+
@data["city"]
|
20
|
+
end
|
21
|
+
|
22
|
+
def city_geoname_id
|
23
|
+
@data["city_geoname_id"]
|
24
|
+
end
|
25
|
+
|
26
|
+
def region_geoname_id
|
27
|
+
@data["region_geoname_id"]
|
28
|
+
end
|
29
|
+
|
30
|
+
def postal_code
|
31
|
+
@data["postal_code"]
|
32
|
+
end
|
33
|
+
|
34
|
+
def country
|
35
|
+
@data["country"]
|
36
|
+
end
|
37
|
+
|
38
|
+
def country_code
|
39
|
+
@data["country_code"]
|
40
|
+
end
|
41
|
+
|
42
|
+
def country_geoname_id
|
43
|
+
@data["country_geoname_id"]
|
44
|
+
end
|
45
|
+
|
46
|
+
def country_is_eu
|
47
|
+
@data["country_is_eu"]
|
48
|
+
end
|
49
|
+
|
50
|
+
def continent
|
51
|
+
@data["continent"]
|
52
|
+
end
|
53
|
+
|
54
|
+
def continent_code
|
55
|
+
@data["continent_code"]
|
56
|
+
end
|
57
|
+
|
58
|
+
def continent_geoname_id
|
59
|
+
@data["continent_geoname_id"]
|
60
|
+
end
|
61
|
+
|
62
|
+
##
|
63
|
+
# Security
|
64
|
+
|
65
|
+
def is_vpn?
|
66
|
+
@data.dig "security", "is_vpn"
|
67
|
+
end
|
68
|
+
|
69
|
+
##
|
70
|
+
# Timezone
|
71
|
+
|
72
|
+
def timezone_name
|
73
|
+
@data.dig "timezone", "name"
|
74
|
+
end
|
75
|
+
|
76
|
+
def timezone_abbreviation
|
77
|
+
@data.dig "timezone", "abbreviation"
|
78
|
+
end
|
79
|
+
|
80
|
+
def timezone_gmt_offset
|
81
|
+
@data.dig "timezone", "gmt_offset"
|
82
|
+
end
|
83
|
+
|
84
|
+
def timezone_current_time
|
85
|
+
@data.dig "timezone", "current_time"
|
86
|
+
end
|
87
|
+
|
88
|
+
def timezone_is_dst
|
89
|
+
@data.dig "timezone", "is_dst"
|
90
|
+
end
|
91
|
+
|
92
|
+
##
|
93
|
+
# Flag
|
94
|
+
|
95
|
+
def flag_emoji
|
96
|
+
@data.dig "flag", "emoji"
|
97
|
+
end
|
98
|
+
|
99
|
+
def flag_unicode
|
100
|
+
@data.dig "flag", "unicode"
|
101
|
+
end
|
102
|
+
|
103
|
+
def flag_png
|
104
|
+
@data.dig "flag", "png"
|
105
|
+
end
|
106
|
+
|
107
|
+
def flag_svg
|
108
|
+
@data.dig "flag", "svg"
|
109
|
+
end
|
110
|
+
|
111
|
+
##
|
112
|
+
# Currency
|
113
|
+
|
114
|
+
def currency_currency_name
|
115
|
+
@data.dig "currency", "currency_name"
|
116
|
+
end
|
117
|
+
|
118
|
+
def currency_currency_code
|
119
|
+
@data.dig "currency", "currency_code"
|
120
|
+
end
|
121
|
+
|
122
|
+
##
|
123
|
+
# Connection
|
124
|
+
|
125
|
+
def connection_autonomous_system_number
|
126
|
+
@data.dig "connection", "autonomous_system_number"
|
127
|
+
end
|
128
|
+
|
129
|
+
def connection_autonomous_system_organization
|
130
|
+
@data.dig "connection", "autonomous_system_organization"
|
131
|
+
end
|
132
|
+
|
133
|
+
def connection_connection_type
|
134
|
+
@data.dig "connection", "connection_type"
|
135
|
+
end
|
136
|
+
|
137
|
+
def connection_isp_name
|
138
|
+
@data.dig "connection", "isp_name"
|
139
|
+
end
|
140
|
+
|
141
|
+
def connection_organization_name
|
142
|
+
@data.dig "connection", "organization_name"
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'geocoder/results/base'
|
2
|
+
|
3
|
+
module Geocoder::Result
|
4
|
+
class AmazonLocationService < Base
|
5
|
+
def initialize(result)
|
6
|
+
@place = result.place
|
7
|
+
super
|
8
|
+
end
|
9
|
+
|
10
|
+
def coordinates
|
11
|
+
[@place.geometry.point[1], @place.geometry.point[0]]
|
12
|
+
end
|
13
|
+
|
14
|
+
def address
|
15
|
+
@place.label
|
16
|
+
end
|
17
|
+
|
18
|
+
def neighborhood
|
19
|
+
@place.neighborhood
|
20
|
+
end
|
21
|
+
|
22
|
+
def route
|
23
|
+
@place.street
|
24
|
+
end
|
25
|
+
|
26
|
+
def city
|
27
|
+
@place.municipality || @place.sub_region
|
28
|
+
end
|
29
|
+
|
30
|
+
def state
|
31
|
+
@place.region
|
32
|
+
end
|
33
|
+
|
34
|
+
def state_code
|
35
|
+
@place.region
|
36
|
+
end
|
37
|
+
|
38
|
+
def province
|
39
|
+
@place.region
|
40
|
+
end
|
41
|
+
|
42
|
+
def province_code
|
43
|
+
@place.region
|
44
|
+
end
|
45
|
+
|
46
|
+
def postal_code
|
47
|
+
@place.postal_code
|
48
|
+
end
|
49
|
+
|
50
|
+
def country
|
51
|
+
@place.country
|
52
|
+
end
|
53
|
+
|
54
|
+
def country_code
|
55
|
+
@place.country
|
56
|
+
end
|
57
|
+
|
58
|
+
def place_id
|
59
|
+
data.place_id if data.respond_to?(:place_id)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|