X-Git-Url: https://git.openstreetmap.org/rails.git/blobdiff_plain/35458c009652645972a9167d80aba1c4fdce82cf..ccebb796ab50c40fed7b76b9b2a7934cbca19cdb:/app/controllers/geocoder_controller.rb diff --git a/app/controllers/geocoder_controller.rb b/app/controllers/geocoder_controller.rb index 592ff020a..7eb817333 100644 --- a/app/controllers/geocoder_controller.rb +++ b/app/controllers/geocoder_controller.rb @@ -7,14 +7,16 @@ class GeocoderController < ApplicationController before_filter :authorize_web before_filter :set_locale + before_filter :require_oauth, :only => [:search] def search normalize_params @sources = [] if params[:lat] && params[:lon] + @sources.push "latlon" @sources.push "osm_nominatim_reverse" - @sources.push "geonames_reverse" + @sources.push "geonames_reverse" if defined?(GEONAMES_USERNAME) elsif params[:query].match(/^\d{5}(-\d{4})?$/) @sources.push "us_postcode" @sources.push "osm_nominatim" @@ -32,6 +34,24 @@ class GeocoderController < ApplicationController render :layout => map_layout end + def search_latlon + lat = params[:lat].to_f + lon = params[:lon].to_f + if lat < -90 or lat > 90 + @error = "Latitude #{lat} out of range" + render :action => "error" + elsif lon < -180 or lon > 180 + @error = "Longitude #{lon} out of range" + render :action => "error" + else + @results = [{:lat => lat, :lon => lon, + :zoom => params[:zoom], + :name => "#{lat}, #{lon}"}] + + render :action => "results" + end + end + def search_us_postcode # get query parameters query = params[:query] @@ -143,7 +163,11 @@ class GeocoderController < ApplicationController type = place.attributes["type"].to_s name = place.attributes["display_name"].to_s min_lat,max_lat,min_lon,max_lon = place.attributes["boundingbox"].to_s.split(",") - prefix_name = t "geocoder.search_osm_nominatim.prefix.#{klass}.#{type}", :default => type.gsub("_", " ").capitalize + if type.empty? + prefix_name = "" + else + prefix_name = t "geocoder.search_osm_nominatim.prefix.#{klass}.#{type}", :default => type.gsub("_", " ").capitalize + end if klass == 'boundary' and type == 'administrative' rank = (place.attributes["place_rank"].to_i + 1) / 2 prefix_name = t "geocoder.search_osm_nominatim.admin_levels.level#{rank}", :default => prefix_name @@ -235,7 +259,7 @@ class GeocoderController < ApplicationController @results = Array.new # ask geonames.org - response = fetch_xml("http://ws.geonames.org/countrySubdivision?lat=#{lat}&lng=#{lon}") + response = fetch_xml("http://api.geonames.org/countrySubdivision?lat=#{lat}&lng=#{lon}&username=#{GEONAMES_USERNAME}") # parse the response response.elements.each("geonames/countrySubdivision") do |geoname|