From 30f8a7004f0ee71d1ae3837fc70235514f6bfa2d Mon Sep 17 00:00:00 2001 From: Chris Myers <chris@cbmyers.com> Date: Mon, 3 Oct 2011 15:20:04 -0400 Subject: [PATCH] fixed a couple bugs --- lib/geocoder/lookups/nominatim.rb | 29 +++++++++++++++++++++-------- lib/geocoder/results/nominatim.rb | 6 +++--- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/lib/geocoder/lookups/nominatim.rb b/lib/geocoder/lookups/nominatim.rb index fc01ad62..7e4f85de 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 b5d0f9bf..f81071e7 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 -- GitLab