geocoder 1.1.9 → 1.3.7

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of geocoder might be problematic. Click here for more details.

Files changed (174) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +157 -0
  3. data/README.md +467 -70
  4. data/examples/reverse_geocode_job.rb +40 -0
  5. data/lib/generators/geocoder/config/templates/initializer.rb +16 -16
  6. data/lib/generators/geocoder/maxmind/geolite_city_generator.rb +28 -0
  7. data/lib/generators/geocoder/maxmind/geolite_country_generator.rb +28 -0
  8. data/lib/generators/geocoder/maxmind/templates/migration/geolite_city.rb +30 -0
  9. data/lib/generators/geocoder/maxmind/templates/migration/geolite_country.rb +17 -0
  10. data/lib/geocoder/cache.rb +3 -2
  11. data/lib/geocoder/calculations.rb +44 -2
  12. data/lib/geocoder/configuration.rb +17 -10
  13. data/lib/geocoder/esri_token.rb +38 -0
  14. data/lib/geocoder/exceptions.rb +19 -0
  15. data/lib/geocoder/ip_address.rb +13 -0
  16. data/lib/geocoder/kernel_logger.rb +25 -0
  17. data/lib/geocoder/logger.rb +47 -0
  18. data/lib/geocoder/lookup.rb +32 -8
  19. data/lib/geocoder/lookups/baidu.rb +18 -13
  20. data/lib/geocoder/lookups/baidu_ip.rb +59 -0
  21. data/lib/geocoder/lookups/base.rb +81 -19
  22. data/lib/geocoder/lookups/bing.rb +40 -7
  23. data/lib/geocoder/lookups/esri.rb +42 -5
  24. data/lib/geocoder/lookups/freegeoip.rb +9 -1
  25. data/lib/geocoder/lookups/geocoder_ca.rb +1 -2
  26. data/lib/geocoder/lookups/geocoder_us.rb +6 -2
  27. data/lib/geocoder/lookups/geocodio.rb +42 -0
  28. data/lib/geocoder/lookups/geoip2.rb +45 -0
  29. data/lib/geocoder/lookups/geoportail_lu.rb +65 -0
  30. data/lib/geocoder/lookups/google.rb +29 -5
  31. data/lib/geocoder/lookups/google_places_details.rb +50 -0
  32. data/lib/geocoder/lookups/google_premier.rb +1 -1
  33. data/lib/geocoder/lookups/here.rb +62 -0
  34. data/lib/geocoder/lookups/ipapi_com.rb +86 -0
  35. data/lib/geocoder/lookups/ipinfo_io.rb +55 -0
  36. data/lib/geocoder/lookups/latlon.rb +59 -0
  37. data/lib/geocoder/lookups/mapbox.rb +53 -0
  38. data/lib/geocoder/lookups/mapquest.rb +6 -6
  39. data/lib/geocoder/lookups/mapzen.rb +15 -0
  40. data/lib/geocoder/lookups/maxmind.rb +4 -2
  41. data/lib/geocoder/lookups/maxmind_geoip2.rb +69 -0
  42. data/lib/geocoder/lookups/maxmind_local.rb +65 -0
  43. data/lib/geocoder/lookups/nominatim.rb +9 -1
  44. data/lib/geocoder/lookups/okf.rb +44 -0
  45. data/lib/geocoder/lookups/opencagedata.rb +58 -0
  46. data/lib/geocoder/lookups/pelias.rb +64 -0
  47. data/lib/geocoder/lookups/pointpin.rb +68 -0
  48. data/lib/geocoder/lookups/postcode_anywhere_uk.rb +51 -0
  49. data/lib/geocoder/lookups/smarty_streets.rb +53 -0
  50. data/lib/geocoder/lookups/telize.rb +55 -0
  51. data/lib/geocoder/lookups/yandex.rb +8 -4
  52. data/lib/geocoder/models/active_record.rb +7 -3
  53. data/lib/geocoder/models/base.rb +1 -4
  54. data/lib/geocoder/models/mongo_base.rb +6 -4
  55. data/lib/geocoder/query.rb +9 -5
  56. data/lib/geocoder/railtie.rb +1 -1
  57. data/lib/geocoder/request.rb +74 -12
  58. data/lib/geocoder/results/baidu_ip.rb +62 -0
  59. data/lib/geocoder/results/bing.rb +4 -0
  60. data/lib/geocoder/results/esri.rb +30 -6
  61. data/lib/geocoder/results/freegeoip.rb +2 -2
  62. data/lib/geocoder/results/geocodio.rb +70 -0
  63. data/lib/geocoder/results/geoip2.rb +62 -0
  64. data/lib/geocoder/results/geoportail_lu.rb +69 -0
  65. data/lib/geocoder/results/google.rb +15 -0
  66. data/lib/geocoder/results/google_places_details.rb +35 -0
  67. data/lib/geocoder/results/here.rb +71 -0
  68. data/lib/geocoder/results/ipapi_com.rb +45 -0
  69. data/lib/geocoder/results/ipinfo_io.rb +48 -0
  70. data/lib/geocoder/results/latlon.rb +71 -0
  71. data/lib/geocoder/results/mapbox.rb +47 -0
  72. data/lib/geocoder/results/mapquest.rb +5 -8
  73. data/lib/geocoder/results/mapzen.rb +5 -0
  74. data/lib/geocoder/results/maxmind_geoip2.rb +9 -0
  75. data/lib/geocoder/results/maxmind_local.rb +49 -0
  76. data/lib/geocoder/results/nominatim.rb +6 -1
  77. data/lib/geocoder/results/okf.rb +106 -0
  78. data/lib/geocoder/results/opencagedata.rb +90 -0
  79. data/lib/geocoder/results/ovi.rb +9 -0
  80. data/lib/geocoder/results/pelias.rb +58 -0
  81. data/lib/geocoder/results/pointpin.rb +40 -0
  82. data/lib/geocoder/results/postcode_anywhere_uk.rb +42 -0
  83. data/lib/geocoder/results/smarty_streets.rb +106 -0
  84. data/lib/geocoder/results/telize.rb +45 -0
  85. data/lib/geocoder/results/test.rb +20 -3
  86. data/lib/geocoder/results/yandex.rb +18 -6
  87. data/lib/geocoder/sql.rb +16 -15
  88. data/lib/geocoder/stores/active_record.rb +51 -18
  89. data/lib/geocoder/stores/base.rb +8 -12
  90. data/lib/geocoder/stores/mongo_base.rb +0 -31
  91. data/lib/geocoder/version.rb +1 -1
  92. data/lib/geocoder.rb +6 -13
  93. data/lib/maxmind_database.rb +109 -0
  94. data/lib/tasks/geocoder.rake +14 -3
  95. data/lib/tasks/maxmind.rake +73 -0
  96. metadata +59 -85
  97. data/.gitignore +0 -5
  98. data/.travis.yml +0 -27
  99. data/Rakefile +0 -25
  100. data/gemfiles/Gemfile.mongoid-2.4.x +0 -15
  101. data/lib/geocoder/lookups/yahoo.rb +0 -86
  102. data/lib/geocoder/results/yahoo.rb +0 -55
  103. data/lib/oauth_util.rb +0 -112
  104. data/test/active_record_test.rb +0 -15
  105. data/test/cache_test.rb +0 -35
  106. data/test/calculations_test.rb +0 -211
  107. data/test/configuration_test.rb +0 -78
  108. data/test/custom_block_test.rb +0 -32
  109. data/test/error_handling_test.rb +0 -43
  110. data/test/fixtures/baidu_invalid_key +0 -1
  111. data/test/fixtures/baidu_no_results +0 -1
  112. data/test/fixtures/baidu_reverse +0 -1
  113. data/test/fixtures/baidu_shanghai_pearl_tower +0 -12
  114. data/test/fixtures/bing_invalid_key +0 -1
  115. data/test/fixtures/bing_madison_square_garden +0 -40
  116. data/test/fixtures/bing_no_results +0 -16
  117. data/test/fixtures/bing_reverse +0 -42
  118. data/test/fixtures/esri_madison_square_garden +0 -59
  119. data/test/fixtures/esri_no_results +0 -8
  120. data/test/fixtures/esri_reverse +0 -21
  121. data/test/fixtures/freegeoip_74_200_247_59 +0 -12
  122. data/test/fixtures/freegeoip_no_results +0 -1
  123. data/test/fixtures/geocoder_ca_madison_square_garden +0 -1
  124. data/test/fixtures/geocoder_ca_no_results +0 -1
  125. data/test/fixtures/geocoder_ca_reverse +0 -34
  126. data/test/fixtures/geocoder_us_madison_square_garden +0 -1
  127. data/test/fixtures/geocoder_us_no_results +0 -1
  128. data/test/fixtures/google_garbage +0 -456
  129. data/test/fixtures/google_madison_square_garden +0 -57
  130. data/test/fixtures/google_no_city_data +0 -44
  131. data/test/fixtures/google_no_locality +0 -51
  132. data/test/fixtures/google_no_results +0 -4
  133. data/test/fixtures/google_over_limit +0 -4
  134. data/test/fixtures/mapquest_error +0 -16
  135. data/test/fixtures/mapquest_invalid_api_key +0 -16
  136. data/test/fixtures/mapquest_invalid_request +0 -16
  137. data/test/fixtures/mapquest_madison_square_garden +0 -52
  138. data/test/fixtures/mapquest_no_results +0 -16
  139. data/test/fixtures/maxmind_24_24_24_21 +0 -1
  140. data/test/fixtures/maxmind_24_24_24_22 +0 -1
  141. data/test/fixtures/maxmind_24_24_24_23 +0 -1
  142. data/test/fixtures/maxmind_24_24_24_24 +0 -1
  143. data/test/fixtures/maxmind_74_200_247_59 +0 -1
  144. data/test/fixtures/maxmind_invalid_key +0 -1
  145. data/test/fixtures/maxmind_no_results +0 -1
  146. data/test/fixtures/nominatim_madison_square_garden +0 -150
  147. data/test/fixtures/nominatim_no_results +0 -1
  148. data/test/fixtures/ovi_madison_square_garden +0 -72
  149. data/test/fixtures/ovi_no_results +0 -8
  150. data/test/fixtures/yahoo_error +0 -1
  151. data/test/fixtures/yahoo_invalid_key +0 -2
  152. data/test/fixtures/yahoo_madison_square_garden +0 -52
  153. data/test/fixtures/yahoo_no_results +0 -10
  154. data/test/fixtures/yahoo_over_limit +0 -2
  155. data/test/fixtures/yandex_invalid_key +0 -1
  156. data/test/fixtures/yandex_kremlin +0 -48
  157. data/test/fixtures/yandex_no_city_and_town +0 -112
  158. data/test/fixtures/yandex_no_results +0 -16
  159. data/test/geocoder_test.rb +0 -59
  160. data/test/https_test.rb +0 -16
  161. data/test/integration/smoke_test.rb +0 -26
  162. data/test/lookup_test.rb +0 -117
  163. data/test/method_aliases_test.rb +0 -25
  164. data/test/mongoid_test.rb +0 -46
  165. data/test/mongoid_test_helper.rb +0 -43
  166. data/test/near_test.rb +0 -61
  167. data/test/oauth_util_test.rb +0 -30
  168. data/test/proxy_test.rb +0 -36
  169. data/test/query_test.rb +0 -52
  170. data/test/request_test.rb +0 -29
  171. data/test/result_test.rb +0 -42
  172. data/test/services_test.rb +0 -393
  173. data/test/test_helper.rb +0 -289
  174. data/test/test_mode_test.rb +0 -59
@@ -35,6 +35,10 @@ module Geocoder::Result
35
35
  @data['address']
36
36
  end
37
37
 
38
+ def viewport
39
+ @data['bbox']
40
+ end
41
+
38
42
  def self.response_attributes
39
43
  %w[bbox name confidence entityType]
40
44
  end
@@ -4,12 +4,16 @@ module Geocoder::Result
4
4
  class Esri < Base
5
5
 
6
6
  def address
7
- address = reverse_geocode? ? 'Address' : 'Match_addr'
8
- attributes[address]
7
+ address_key = reverse_geocode? ? 'Address' : 'Match_addr'
8
+ attributes[address_key]
9
9
  end
10
10
 
11
11
  def city
12
- attributes['City']
12
+ if !reverse_geocode? && is_city?
13
+ place_name
14
+ else
15
+ attributes['City']
16
+ end
13
17
  end
14
18
 
15
19
  def state_code
@@ -19,8 +23,8 @@ module Geocoder::Result
19
23
  alias_method :state, :state_code
20
24
 
21
25
  def country
22
- country = reverse_geocode? ? "CountryCode" : "Country"
23
- attributes[country]
26
+ country_key = reverse_geocode? ? "CountryCode" : "Country"
27
+ attributes[country_key]
24
28
  end
25
29
 
26
30
  alias_method :country_code, :country
@@ -29,10 +33,27 @@ module Geocoder::Result
29
33
  attributes['Postal']
30
34
  end
31
35
 
36
+ def place_name
37
+ place_name_key = reverse_geocode? ? "Address" : "PlaceName"
38
+ attributes[place_name_key]
39
+ end
40
+
41
+ def place_type
42
+ reverse_geocode? ? "Address" : attributes['Type']
43
+ end
44
+
32
45
  def coordinates
33
46
  [geometry["y"], geometry["x"]]
34
47
  end
35
48
 
49
+ def viewport
50
+ north = attributes['Ymax']
51
+ south = attributes['Ymin']
52
+ east = attributes['Xmax']
53
+ west = attributes['Xmin']
54
+ [south, west, north, east]
55
+ end
56
+
36
57
  private
37
58
 
38
59
  def attributes
@@ -47,5 +68,8 @@ module Geocoder::Result
47
68
  @data['locations'].nil?
48
69
  end
49
70
 
71
+ def is_city?
72
+ ['City', 'State Capital', 'National Capital'].include?(place_type)
73
+ end
50
74
  end
51
- end
75
+ end
@@ -29,11 +29,11 @@ module Geocoder::Result
29
29
  end
30
30
 
31
31
  def postal_code
32
- @data['zipcode']
32
+ @data['zipcode'] || @data['zip_code']
33
33
  end
34
34
 
35
35
  def self.response_attributes
36
- %w[metrocode ip]
36
+ %w[metro_code ip]
37
37
  end
38
38
 
39
39
  response_attributes.each do |a|
@@ -0,0 +1,70 @@
1
+ require 'geocoder/results/base'
2
+
3
+ module Geocoder::Result
4
+ class Geocodio < Base
5
+ def number
6
+ address_components["number"]
7
+ end
8
+
9
+ def street
10
+ address_components["street"]
11
+ end
12
+
13
+ def suffix
14
+ address_components["suffix"]
15
+ end
16
+
17
+ def street_address
18
+ [number, address_components["formatted_street"]].compact.join(' ')
19
+ end
20
+
21
+ def state
22
+ address_components["state"]
23
+ end
24
+ alias_method :state_code, :state
25
+
26
+ def zip
27
+ address_components["zip"]
28
+ end
29
+ alias_method :postal_code, :zip
30
+
31
+ def country
32
+ "United States" # Geocodio only supports the US
33
+ end
34
+
35
+ def country_code
36
+ "US" # Geocodio only supports the US
37
+ end
38
+
39
+ def city
40
+ address_components["city"]
41
+ end
42
+
43
+ def postdirectional
44
+ address_components["postdirectional"]
45
+ end
46
+
47
+ def location
48
+ @data['location']
49
+ end
50
+
51
+ def coordinates
52
+ ['lat', 'lng'].map{ |i| location[i].to_f } if location
53
+ end
54
+
55
+ def accuracy
56
+ @data['accuracy'].to_f if @data.key?('accuracy')
57
+ end
58
+
59
+ def formatted_address(format = :full)
60
+ @data['formatted_address']
61
+ end
62
+ alias_method :address, :formatted_address
63
+
64
+ private
65
+
66
+ def address_components
67
+ @data['address_components'] || {}
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,62 @@
1
+ require 'geocoder/results/base'
2
+
3
+ module Geocoder
4
+ module Result
5
+ class Geoip2 < Base
6
+ def address(format = :full)
7
+ s = state.to_s == '' ? '' : ", #{state_code}"
8
+ "#{city}#{s} #{postal_code}, #{country}".sub(/^[ ,]*/, '')
9
+ end
10
+
11
+ def coordinates
12
+ %w[latitude longitude].map do |l|
13
+ data.fetch('location', {}).fetch(l, 0.0)
14
+ end
15
+ end
16
+
17
+ def city
18
+ data.fetch('city', {}).fetch('names', {}).fetch(locale, '')
19
+ end
20
+
21
+ def state
22
+ data.fetch('subdivisions', []).fetch(0, {}).fetch('names', {}).fetch(locale, '')
23
+ end
24
+
25
+ def state_code
26
+ data.fetch('subdivisions', []).fetch(0, {}).fetch('iso_code', '')
27
+ end
28
+
29
+ def country
30
+ data.fetch('country', {}).fetch('names', {}).fetch(locale, '')
31
+ end
32
+
33
+ def country_code
34
+ data.fetch('country', {}).fetch('iso_code', '')
35
+ end
36
+
37
+ def postal_code
38
+ data.fetch('postal', {}).fetch('code', '')
39
+ end
40
+
41
+ def self.response_attributes
42
+ %w[ip]
43
+ end
44
+
45
+ response_attributes.each do |a|
46
+ define_method a do
47
+ @data[a]
48
+ end
49
+ end
50
+
51
+ private
52
+
53
+ def data
54
+ @data.to_hash
55
+ end
56
+
57
+ def locale
58
+ @locale ||= Geocoder.config[:language].to_s
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,69 @@
1
+ require 'geocoder/results/base'
2
+
3
+ module Geocoder::Result
4
+ class GeoportailLu < Base
5
+
6
+ def coordinates
7
+ geomlonlat['coordinates'].reverse if geolocalized?
8
+ end
9
+
10
+ def address
11
+ full_address
12
+ end
13
+
14
+ def city
15
+ try_to_extract 'locality', detailled_address
16
+ end
17
+
18
+ def state
19
+ 'Luxembourg'
20
+ end
21
+
22
+ def state_code
23
+ 'LU'
24
+ end
25
+
26
+ def postal_code
27
+ try_to_extract 'zip', detailled_address
28
+ end
29
+
30
+ def street_address
31
+ [street_number, street].compact.join(' ')
32
+ end
33
+
34
+ def street_number
35
+ try_to_extract 'postnumber', detailled_address
36
+ end
37
+
38
+ def street
39
+ try_to_extract 'street', detailled_address
40
+ end
41
+
42
+ def full_address
43
+ data['address']
44
+ end
45
+
46
+ def geomlonlat
47
+ data['geomlonlat']
48
+ end
49
+
50
+ def detailled_address
51
+ data['AddressDetails']
52
+ end
53
+
54
+ alias_method :country, :state
55
+ alias_method :province, :state
56
+ alias_method :country_code, :state_code
57
+ alias_method :province_code, :state_code
58
+
59
+ private
60
+
61
+ def geolocalized?
62
+ try_to_extract('coordinates', geomlonlat).present?
63
+ end
64
+
65
+ def try_to_extract(key, nullable_hash)
66
+ nullable_hash.try(:[], key)
67
+ end
68
+ end
69
+ end
@@ -120,5 +120,20 @@ module Geocoder::Result
120
120
  def precision
121
121
  geometry['location_type'] if geometry
122
122
  end
123
+
124
+ def partial_match
125
+ @data['partial_match']
126
+ end
127
+
128
+ def place_id
129
+ @data['place_id']
130
+ end
131
+
132
+ def viewport
133
+ viewport = geometry['viewport'] || fail
134
+ south, west = %w(lat lng).map { |c| viewport['southwest'][c] }
135
+ north, east = %w(lat lng).map { |c| viewport['northeast'][c] }
136
+ [south, west, north, east]
137
+ end
123
138
  end
124
139
  end
@@ -0,0 +1,35 @@
1
+ require "geocoder/results/google"
2
+
3
+ module Geocoder
4
+ module Result
5
+ class GooglePlacesDetails < Google
6
+ def place_id
7
+ @data["place_id"]
8
+ end
9
+
10
+ def types
11
+ @data["types"] || []
12
+ end
13
+
14
+ def reviews
15
+ @data["reviews"] || []
16
+ end
17
+
18
+ def rating
19
+ @data["rating"]
20
+ end
21
+
22
+ def rating_count
23
+ @data["user_ratings_total"]
24
+ end
25
+
26
+ def phone_number
27
+ @data["international_phone_number"]
28
+ end
29
+
30
+ def website
31
+ @data["website"]
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,71 @@
1
+ require 'geocoder/results/base'
2
+
3
+ module Geocoder::Result
4
+ class Here < Base
5
+
6
+ ##
7
+ # A string in the given format.
8
+ #
9
+ def address(format = :full)
10
+ address_data['Label']
11
+ end
12
+
13
+ ##
14
+ # A two-element array: [lat, lon].
15
+ #
16
+ def coordinates
17
+ fail unless d = @data['Location']['DisplayPosition']
18
+ [d['Latitude'].to_f, d['Longitude'].to_f]
19
+ end
20
+
21
+ def state
22
+ address_data['County']
23
+ end
24
+
25
+ def province
26
+ address_data['County']
27
+ end
28
+
29
+ def postal_code
30
+ address_data['PostalCode']
31
+ end
32
+
33
+ def city
34
+ address_data['City']
35
+ end
36
+
37
+ def state_code
38
+ address_data['State']
39
+ end
40
+
41
+ def province_code
42
+ address_data['State']
43
+ end
44
+
45
+ def country
46
+ fail unless d = address_data['AdditionalData']
47
+ if v = d.find{|ad| ad['key']=='CountryName'}
48
+ return v['value']
49
+ end
50
+ end
51
+
52
+ def country_code
53
+ address_data['Country']
54
+ end
55
+
56
+ def viewport
57
+ map_view = data['Location']['MapView'] || fail
58
+ south = map_view['BottomRight']['Latitude']
59
+ west = map_view['TopLeft']['Longitude']
60
+ north = map_view['TopLeft']['Latitude']
61
+ east = map_view['BottomRight']['Longitude']
62
+ [south, west, north, east]
63
+ end
64
+
65
+ private # ----------------------------------------------------------------
66
+
67
+ def address_data
68
+ @data['Location']['Address'] || fail
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,45 @@
1
+ require 'geocoder/results/base'
2
+
3
+ module Geocoder::Result
4
+ class IpapiCom < Base
5
+
6
+ def coordinates
7
+ [lat, lon]
8
+ end
9
+
10
+ def address
11
+ "#{city}, #{state_code} #{postal_code}, #{country}".sub(/^[ ,]*/, "")
12
+ end
13
+
14
+ def state
15
+ region_name
16
+ end
17
+
18
+ def state_code
19
+ region
20
+ end
21
+
22
+ def postal_code
23
+ zip
24
+ end
25
+
26
+ def country_code
27
+ @data['countryCode']
28
+ end
29
+
30
+ def region_name
31
+ @data['regionName']
32
+ end
33
+
34
+ def self.response_attributes
35
+ %w[country region city zip timezone isp org as reverse query status message mobile proxy lat lon]
36
+ end
37
+
38
+ response_attributes.each do |attribute|
39
+ define_method attribute do
40
+ @data[attribute]
41
+ end
42
+ end
43
+
44
+ end
45
+ end
@@ -0,0 +1,48 @@
1
+ require 'geocoder/results/base'
2
+
3
+ module Geocoder::Result
4
+ class IpinfoIo < Base
5
+
6
+ def address(format = :full)
7
+ "#{city} #{postal_code}, #{country}".sub(/^[ ,]*/, "")
8
+ end
9
+
10
+ def coordinates
11
+ @data['loc'].split(",").map(&:to_f)
12
+ end
13
+
14
+ def city
15
+ @data['city']
16
+ end
17
+
18
+ def state
19
+ @data['region']
20
+ end
21
+
22
+ def country
23
+ @data['country']
24
+ end
25
+
26
+ def postal_code
27
+ @data['postal']
28
+ end
29
+
30
+ def country_code
31
+ @data.fetch('country', '')
32
+ end
33
+
34
+ def state_code
35
+ @data.fetch('region_code', '')
36
+ end
37
+
38
+ def self.response_attributes
39
+ %w['ip', 'region', 'postal']
40
+ end
41
+
42
+ response_attributes.each do |a|
43
+ define_method a do
44
+ @data[a]
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,71 @@
1
+ require 'geocoder/results/base'
2
+
3
+ module Geocoder::Result
4
+ class Latlon < Base
5
+
6
+ def city
7
+ address_components["city"]
8
+ end
9
+
10
+ def coordinates
11
+ [@data['lat'].to_f, @data['lon'].to_f]
12
+ end
13
+
14
+ def country
15
+ "United States" # LatLon.io only supports the US
16
+ end
17
+
18
+ def country_code
19
+ "US" # LatLon.io only supports the US
20
+ end
21
+
22
+ def formatted_address(format = :full)
23
+ address_components["address"]
24
+ end
25
+ alias_method :address, :formatted_address
26
+
27
+ def number
28
+ address_components["number"]
29
+ end
30
+
31
+ def prefix
32
+ address_components["prefix"]
33
+ end
34
+
35
+ def state
36
+ address_components["state"]
37
+ end
38
+ alias_method :state_code, :state
39
+
40
+ def street
41
+ [street_name, street_type].compact.join(' ')
42
+ end
43
+
44
+ def street_name
45
+ address_components["street_name"]
46
+ end
47
+
48
+ def street_type
49
+ address_components["street_type"]
50
+ end
51
+
52
+ def suffix
53
+ address_components["suffix"]
54
+ end
55
+
56
+ def unit
57
+ address_components["unit"]
58
+ end
59
+
60
+ def zip
61
+ address_components["zip"]
62
+ end
63
+ alias_method :postal_code, :zip
64
+
65
+ private
66
+
67
+ def address_components
68
+ @data["address"] || {}
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,47 @@
1
+ require 'geocoder/results/base'
2
+
3
+ module Geocoder::Result
4
+ class Mapbox < Base
5
+
6
+ def coordinates
7
+ @data["geometry"]["coordinates"].reverse.map(&:to_f)
8
+ end
9
+
10
+ def place_name
11
+ @data['text']
12
+ end
13
+
14
+ def street
15
+ @data['properties']['address']
16
+ end
17
+
18
+ def city
19
+ @data['context'].map { |c| c['text'] if c['id'] =~ /place/ }.compact.first
20
+ end
21
+
22
+ def state
23
+ @data['context'].map { |c| c['text'] if c['id'] =~ /region/ }.compact.first
24
+ end
25
+
26
+ alias_method :state_code, :state
27
+
28
+ def postal_code
29
+ @data['context'].map { |c| c['text'] if c['id'] =~ /postcode/ }.compact.first
30
+ end
31
+
32
+ def country
33
+ @data['context'].map { |c| c['text'] if c['id'] =~ /country/ }.compact.first
34
+ end
35
+
36
+ alias_method :country_code, :country
37
+
38
+ def neighborhood
39
+ @data['context'].map { |c| c['text'] if c['id'] =~ /neighborhood/ }.compact.first
40
+ end
41
+
42
+ def address
43
+ [place_name, street, city, state, postal_code, country].compact.join(", ")
44
+ end
45
+ end
46
+ end
47
+
@@ -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
- [latitude, longitude]
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
@@ -0,0 +1,5 @@
1
+ require 'geocoder/results/pelias'
2
+
3
+ module Geocoder::Result
4
+ class Mapzen < Pelias; end
5
+ 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