diff --git a/lib/geocoder/lookups/nominatim.rb b/lib/geocoder/lookups/nominatim.rb index fc01ad62537e643104ec6229647e784fffcee68b..7e4f85de895795e8db9b98e235a0c501ba7739ba 100644 --- a/lib/geocoder/lookups/nominatim.rb +++ b/lib/geocoder/lookups/nominatim.rb @@ -10,23 +10,36 @@ module Geocoder::Lookup def results(query, reverse = false) return [] unless doc = fetch_data(query, reverse) - if doc.any? - return doc[0]['place_id'] != "" ? doc : [] - else - warn "Nominatim Geocoding Adress not founr or API error." - return [] - end + if doc.kind_of?(Array) + if doc.any? + return doc[0]['place_id'] != "" ? doc : [] + else + warn "Address not found or Nominatim Geocoding API error." + return [] + end + else + return doc['place_id'] != "" ? doc = [] << doc : [] + end end def query_url(query, reverse = false) params = { - :q => query, :format => "json", :polygon => "1", :addressdetails => "1", # :locale => "#{Geocoder::Configuration.language}_US", } - "http://nominatim.openstreetmap.org/search?" + hash_to_query(params) + if (reverse) + method = 'reverse' + parts = query.split(/\s*,\s*/); + params[:lat] = parts[0] + params[:lon] = parts[1] + else + method = 'search' + params[:q] = query + end + "http://nominatim.openstreetmap.org/#{method}?" + hash_to_query(params) end + end end \ No newline at end of file diff --git a/lib/geocoder/results/nominatim.rb b/lib/geocoder/results/nominatim.rb index b5d0f9bf191e372c5dcd926698dce0a49a570831..f81071e762cc81b6685b3da545ba02cd819fbcc0 100644 --- a/lib/geocoder/results/nominatim.rb +++ b/lib/geocoder/results/nominatim.rb @@ -31,12 +31,12 @@ module Geocoder::Result @data['address']['state'] end + alias_method :state_code, :state + def postal_code @data['address']['postcode'] end - - alias_method :state, :state_code - + def county @data['address']['county'] end