Use api.geonames.org for reverse searches
[rails.git] / app / controllers / geocoder_controller.rb
index 692ae24ddb2e892d89bbc50e663a9af668e96b67..7eb81733314ae8a235224281352afb4184916775 100644 (file)
@@ -16,7 +16,7 @@ class GeocoderController < ApplicationController
     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"
@@ -259,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|