Use api.geonames.org for reverse searches
authorTom Hughes <tom@compton.nu>
Mon, 27 Jan 2014 21:02:00 +0000 (21:02 +0000)
committerTom Hughes <tom@compton.nu>
Mon, 27 Jan 2014 21:14:17 +0000 (21:14 +0000)
app/controllers/geocoder_controller.rb
test/functional/geocoder_controller_test.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|
index f1b12f21d439776c94eb66925af74e57c169c81f..607e929c11e1d877609900038d5d336cc383d35e 100644 (file)
@@ -170,12 +170,7 @@ class GeocoderControllerTest < ActionController::TestCase
      'S50 4.064 W14 22.645',
      "50° 04.064' S, 014° 22.645' W"
     ].each do |code|
-      post :search, :query => code
-      assert_response :success
-      assert_equal ['latlon' ,'osm_nominatim_reverse', 'geonames_reverse'], assigns(:sources)
-      assert_nil @controller.params[:query]
-      assert_in_delta -50.06773, @controller.params[:lat]
-      assert_in_delta -14.37742, @controller.params[:lon]
+      latlon_check code, -50.06773, -14.37742
     end
   end
 
@@ -286,7 +281,7 @@ private
     assert_response :success
     assert_template "search"
     assert_template :layout => "map"
-    assert_equal ['latlon' ,'osm_nominatim_reverse', 'geonames_reverse'], assigns(:sources)
+    assert_equal ['latlon' ,'osm_nominatim_reverse'], assigns(:sources)
     assert_nil @controller.params[:query]
     assert_in_delta lat, @controller.params[:lat]
     assert_in_delta lon, @controller.params[:lon]
@@ -295,7 +290,7 @@ private
     assert_response :success
     assert_template "search"
     assert_template :layout => "xhr"
-    assert_equal ['latlon' ,'osm_nominatim_reverse', 'geonames_reverse'], assigns(:sources)
+    assert_equal ['latlon' ,'osm_nominatim_reverse'], assigns(:sources)
     assert_nil @controller.params[:query]
     assert_in_delta lat, @controller.params[:lat]
     assert_in_delta lon, @controller.params[:lon]