class Geocoder::Result::Geoapify

apidocs.geoapify.com/docs/geocoding/api

Public Instance Methods

address(_format = :full) click to toggle source
# File lib/geocoder/results/geoapify.rb, line 9
def address(_format = :full)
  properties['formatted']
end
address_line1() click to toggle source
# File lib/geocoder/results/geoapify.rb, line 13
def address_line1
  properties['address_line1']
end
address_line2() click to toggle source
# File lib/geocoder/results/geoapify.rb, line 17
def address_line2
  properties['address_line2']
end
bounds() click to toggle source

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

# File lib/geocoder/results/geoapify.rb, line 85
def bounds
  data['bbox']
end
city() click to toggle source
# File lib/geocoder/results/geoapify.rb, line 41
def city
  properties['city']
end
coordinates() click to toggle source
# File lib/geocoder/results/geoapify.rb, line 68
def coordinates
  return unless properties['lat']
  return unless properties['lon']

  [properties['lat'], properties['lon']]
end
country() click to toggle source
# File lib/geocoder/results/geoapify.rb, line 58
def country
  properties['country']
end
country_code() click to toggle source
# File lib/geocoder/results/geoapify.rb, line 62
def country_code
  return unless properties['country_code']

  properties['country_code'].upcase
end
county() click to toggle source
# File lib/geocoder/results/geoapify.rb, line 45
def county
  properties['county']
end
datasource() click to toggle source

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',
}
# File lib/geocoder/results/geoapify.rb, line 156
def datasource
  return unless properties['datasource']

  symbol_hash properties['datasource']
end
distance() click to toggle source

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

# File lib/geocoder/results/geoapify.rb, line 111
def distance
  properties['distance']
end
district() click to toggle source
# File lib/geocoder/results/geoapify.rb, line 33
def district
  properties['district']
end
geometry() click to toggle source

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

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

# File lib/geocoder/results/geoapify.rb, line 78
def geometry
  return unless data['geometry']

  symbol_hash data['geometry']
end
house_number() click to toggle source
# File lib/geocoder/results/geoapify.rb, line 21
def house_number
  properties['housenumber']
end
postal_code() click to toggle source
# File lib/geocoder/results/geoapify.rb, line 29
def postal_code
  properties['postcode']
end
rank() click to toggle source

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
}
# 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
state() click to toggle source
# File lib/geocoder/results/geoapify.rb, line 49
def state
  properties['state']
end
state_code() click to toggle source

Not currently available in the API

# File lib/geocoder/results/geoapify.rb, line 54
def state_code
  ''
end
street() click to toggle source
# File lib/geocoder/results/geoapify.rb, line 25
def street
  properties['street']
end
suburb() click to toggle source
# File lib/geocoder/results/geoapify.rb, line 37
def suburb
  properties['suburb']
end
type() click to toggle source

Type of the result, one of:

* :unknown
* :amenity
* :building
* :street
* :suburb
* :district
* :postcode
* :city
* :county
* :state
* :country
# File lib/geocoder/results/geoapify.rb, line 103
def type
  return :unknown unless properties['result_type']

  properties['result_type'].to_sym
end

Private Instance Methods

properties() click to toggle source
# File lib/geocoder/results/geoapify.rb, line 164
def properties
  @properties ||= data['properties'] || {}
end
symbol_hash(orig_hash) click to toggle source
# File lib/geocoder/results/geoapify.rb, line 168
def symbol_hash(orig_hash)
  {}.tap do |result|
    orig_hash.each_key do |key|
      next unless orig_hash[key]

      result[key.to_sym] = orig_hash[key]
    end
  end
end