2015-08-10 11:05:06 +02:00
|
|
|
module Carto
|
|
|
|
module Bano
|
|
|
|
# input : address
|
|
|
|
# output : point RGeo::Cartesian::PointImpl
|
|
|
|
class PointRetriever
|
|
|
|
def initialize(address)
|
|
|
|
@address = address
|
|
|
|
end
|
|
|
|
|
|
|
|
def point
|
|
|
|
@point ||= convert_driver_result_to_point
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def driver
|
|
|
|
@driver ||= Carto::Bano::Driver.new @address
|
|
|
|
end
|
|
|
|
|
|
|
|
def convert_driver_result_to_point
|
|
|
|
result = JSON.parse(driver.call)
|
2018-10-01 13:53:15 +02:00
|
|
|
if result['features'].empty?
|
2015-08-10 11:05:06 +02:00
|
|
|
Rails.logger.error "unable to find location for address #{@address}"
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
RGeo::GeoJSON.decode(result['features'][0]['geometry'], json_parser: :json)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|