]> git.openstreetmap.org Git - rails.git/blobdiff - app/controllers/geocoder_controller.rb
Minor fixes to the I18n code of routing
[rails.git] / app / controllers / geocoder_controller.rb
index 692ae24ddb2e892d89bbc50e663a9af668e96b67..73422c2f0a3cb0a0d7133ab57aedfd94e0980b05 100644 (file)
@@ -16,7 +16,7 @@ class GeocoderController < ApplicationController
     if params[:lat] && params[:lon]
       @sources.push "latlon"
       @sources.push "osm_nominatim_reverse"
     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"
     elsif params[:query].match(/^\d{5}(-\d{4})?$/)
       @sources.push "us_postcode"
       @sources.push "osm_nominatim"
@@ -194,11 +194,14 @@ class GeocoderController < ApplicationController
     # get query parameters
     query = params[:query]
 
     # get query parameters
     query = params[:query]
 
+    # get preferred language
+    lang = I18n.locale.to_s.split("-").first
+
     # create result array
     @results = Array.new
 
     # ask geonames.org
     # create result array
     @results = Array.new
 
     # ask geonames.org
-    response = fetch_xml("http://api.geonames.org/search?q=#{escape_query(query)}&maxRows=20&username=#{GEONAMES_USERNAME}")
+    response = fetch_xml("http://api.geonames.org/search?q=#{escape_query(query)}&lang=#{lang}&maxRows=20&username=#{GEONAMES_USERNAME}")
 
     # parse the response
     response.elements.each("geonames/geoname") do |geoname|
 
     # parse the response
     response.elements.each("geonames/geoname") do |geoname|
@@ -255,11 +258,14 @@ class GeocoderController < ApplicationController
     lat = params[:lat]
     lon = params[:lon]
 
     lat = params[:lat]
     lon = params[:lon]
 
+    # get preferred language
+    lang = I18n.locale.to_s.split("-").first
+
     # create result array
     @results = Array.new
 
     # ask geonames.org
     # create result array
     @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}&lang=#{lang}&username=#{GEONAMES_USERNAME}")
 
     # parse the response
     response.elements.each("geonames/countrySubdivision") do |geoname|
 
     # parse the response
     response.elements.each("geonames/countrySubdivision") do |geoname|