Class: Geocoder::Result::Geoapify

Inherits:
Base
  • Object
show all
Defined in:
lib/geocoder/results/geoapify.rb

Overview

Instance Attribute Summary

Attributes inherited from Base

#cache_hit, #data

Instance Method Summary collapse

Methods inherited from Base

#initialize, #latitude, #longitude, #province, #province_code

Constructor Details

This class inherits a constructor from Geocoder::Result::Base

Instance Method Details

#address(_format = :full) ⇒ Object


9
10
11
# File 'lib/geocoder/results/geoapify.rb', line 9

def address(_format = :full)
  properties['formatted']
end

#address_line1Object


13
14
15
# File 'lib/geocoder/results/geoapify.rb', line 13

def address_line1
  properties['address_line1']
end

#address_line2Object


17
18
19
# File 'lib/geocoder/results/geoapify.rb', line 17

def address_line2
  properties['address_line2']
end

#boundsObject


85
86
87
# File 'lib/geocoder/results/geoapify.rb', line 85

def bounds
  data['bbox']
end

#cityObject


41
42
43
# File 'lib/geocoder/results/geoapify.rb', line 41

def city
  properties['city']
end

#coordinatesObject


68
69
70
71
72
73
# File 'lib/geocoder/results/geoapify.rb', line 68

def coordinates
  return unless properties['lat']
  return unless properties['lon']

  [properties['lat'], properties['lon']]
end

#countryObject


58
59
60
# File 'lib/geocoder/results/geoapify.rb', line 58

def country
  properties['country']
end

#country_codeObject


62
63
64
65
66
# File 'lib/geocoder/results/geoapify.rb', line 62

def country_code
  return unless properties['country_code']

  properties['country_code'].upcase
end

#countyObject


45
46
47
# File 'lib/geocoder/results/geoapify.rb', line 45

def county
  properties['county']
end

#datasourceObject

Examples:

Open

{
  sourcename: 'openstreetmap',
  wheelchair: 'limited',
  wikidata: 'Q186125',
  wikipedia: 'en:Madison Square Garden',
  website: 'http://www.thegarden.com/',
  phone: '12124656741',
  osm_type: 'W',
  osm_id: 138141251,
  continent: 'North America',
}

156
157
158
159
160
# File 'lib/geocoder/results/geoapify.rb', line 156

def datasource
  return unless properties['datasource']

  symbol_hash properties['datasource']
end

#distanceObject

Distance in meters to given bias:proximity or to given coordinates for reverse geocoding


111
112
113
# File 'lib/geocoder/results/geoapify.rb', line 111

def distance
  properties['distance']
end

#districtObject


33
34
35
# File 'lib/geocoder/results/geoapify.rb', line 33

def district
  properties['district']
end

#geometryObject

See: tools.ietf.org/html/rfc7946#section-3.1

Each feature has a “Point” type in the Geoapify API.


78
79
80
81
82
# File 'lib/geocoder/results/geoapify.rb', line 78

def geometry
  return unless data['geometry']

  symbol_hash data['geometry']
end

#house_numberObject


21
22
23
# File 'lib/geocoder/results/geoapify.rb', line 21

def house_number
  properties['housenumber']
end

#postal_codeObject


29
30
31
# File 'lib/geocoder/results/geoapify.rb', line 29

def postal_code
  properties['postcode']
end

#rankObject

Calculated rank for the result, containing the following keys:

* `popularity` - The popularity score of the result
* `confidence` - The confidence value of the result (0-1)
* `match_type` - The result's match type, one of following:
   * full_match
   * inner_part
   * match_by_building
   * match_by_street
   * match_by_postcode
   * match_by_city_or_disrict
   * match_by_country_or_state

Example:

{
  popularity: 8.615793062435909,
  confidence: 0.88,
  match_type: :full_match
}

134
135
136
137
138
139
140
# File 'lib/geocoder/results/geoapify.rb', line 134

def rank
  return unless properties['rank']

  r = symbol_hash(properties['rank'])
  r[:match_type] = r[:match_type].to_sym if r[:match_type]
  r
end

#stateObject


49
50
51
# File 'lib/geocoder/results/geoapify.rb', line 49

def state
  properties['state']
end

#state_codeObject

Not currently available in the API


54
55
56
# File 'lib/geocoder/results/geoapify.rb', line 54

def state_code
  ''
end

#streetObject


25
26
27
# File 'lib/geocoder/results/geoapify.rb', line 25

def street
  properties['street']
end

#suburbObject


37
38
39
# File 'lib/geocoder/results/geoapify.rb', line 37

def suburb
  properties['suburb']
end

#typeObject

Type of the result, one of:

* :unknown
* :amenity
* :building
* :street
* :suburb
* :district
* :postcode
* :city
* :county
* :state
* :country

103
104
105
106
107
# File 'lib/geocoder/results/geoapify.rb', line 103

def type
  return :unknown unless properties['result_type']

  properties['result_type'].to_sym
end