parent
429641bd90
commit
6209a9be78
5 changed files with 1 additions and 58 deletions
|
@ -19,7 +19,6 @@ class GeocoderController < ApplicationController
|
||||||
@sources.push "geonames_reverse" if defined?(GEONAMES_USERNAME)
|
@sources.push "geonames_reverse" if defined?(GEONAMES_USERNAME)
|
||||||
elsif @params[:query]
|
elsif @params[:query]
|
||||||
if @params[:query] =~ /^\d{5}(-\d{4})?$/
|
if @params[:query] =~ /^\d{5}(-\d{4})?$/
|
||||||
@sources.push "us_postcode"
|
|
||||||
@sources.push "osm_nominatim"
|
@sources.push "osm_nominatim"
|
||||||
elsif @params[:query] =~ /^(GIR 0AA|[A-PR-UWYZ]([0-9]{1,2}|([A-HK-Y][0-9]|[A-HK-Y][0-9]([0-9]|[ABEHMNPRV-Y]))|[0-9][A-HJKS-UW])\s*[0-9][ABD-HJLNP-UW-Z]{2})$/i
|
elsif @params[:query] =~ /^(GIR 0AA|[A-PR-UWYZ]([0-9]{1,2}|([A-HK-Y][0-9]|[A-HK-Y][0-9]([0-9]|[ABEHMNPRV-Y]))|[0-9][A-HJKS-UW])\s*[0-9][ABD-HJLNP-UW-Z]{2})$/i
|
||||||
@sources.push "uk_postcode"
|
@sources.push "uk_postcode"
|
||||||
|
@ -58,31 +57,6 @@ class GeocoderController < ApplicationController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def search_us_postcode
|
|
||||||
# get query parameters
|
|
||||||
query = params[:query]
|
|
||||||
|
|
||||||
# create result array
|
|
||||||
@results = []
|
|
||||||
|
|
||||||
# ask geocoder.us (they have a non-commercial use api)
|
|
||||||
response = fetch_text("http://rpc.geocoder.us/service/csv?zip=#{escape_query(query)}")
|
|
||||||
|
|
||||||
# parse the response
|
|
||||||
unless response =~ /couldn't find this zip/
|
|
||||||
data = response.split(/\s*,\s+/) # lat,long,town,state,zip
|
|
||||||
@results.push(:lat => data[0], :lon => data[1],
|
|
||||||
:zoom => POSTCODE_ZOOM,
|
|
||||||
:prefix => "#{data[2]}, #{data[3]},",
|
|
||||||
:name => data[4])
|
|
||||||
end
|
|
||||||
|
|
||||||
render :action => "results"
|
|
||||||
rescue StandardError => ex
|
|
||||||
@error = "Error contacting rpc.geocoder.us: #{ex}"
|
|
||||||
render :action => "error"
|
|
||||||
end
|
|
||||||
|
|
||||||
def search_uk_postcode
|
def search_uk_postcode
|
||||||
# get query parameters
|
# get query parameters
|
||||||
query = params[:query]
|
query = params[:query]
|
||||||
|
|
|
@ -367,7 +367,6 @@ en:
|
||||||
search:
|
search:
|
||||||
title:
|
title:
|
||||||
latlon: 'Results from <a href="http://openstreetmap.org/">Internal</a>'
|
latlon: 'Results from <a href="http://openstreetmap.org/">Internal</a>'
|
||||||
us_postcode: 'Results from <a href="http://geocoder.us/">Geocoder.us</a>'
|
|
||||||
uk_postcode: 'Results from <a href="http://www.npemap.org.uk/">NPEMap / FreeThe Postcode</a>'
|
uk_postcode: 'Results from <a href="http://www.npemap.org.uk/">NPEMap / FreeThe Postcode</a>'
|
||||||
ca_postcode: 'Results from <a href="http://geocoder.ca/">Geocoder.CA</a>'
|
ca_postcode: 'Results from <a href="http://geocoder.ca/">Geocoder.CA</a>'
|
||||||
osm_nominatim: 'Results from <a href="http://nominatim.openstreetmap.org/">OpenStreetMap Nominatim</a>'
|
osm_nominatim: 'Results from <a href="http://nominatim.openstreetmap.org/">OpenStreetMap Nominatim</a>'
|
||||||
|
|
|
@ -246,7 +246,6 @@ OpenStreetMap::Application.routes.draw do
|
||||||
# geocoder
|
# geocoder
|
||||||
match "/search" => "geocoder#search", :via => :get, :as => :search
|
match "/search" => "geocoder#search", :via => :get, :as => :search
|
||||||
match "/geocoder/search_latlon" => "geocoder#search_latlon", :via => :get
|
match "/geocoder/search_latlon" => "geocoder#search_latlon", :via => :get
|
||||||
match "/geocoder/search_us_postcode" => "geocoder#search_us_postcode", :via => :get
|
|
||||||
match "/geocoder/search_uk_postcode" => "geocoder#search_uk_postcode", :via => :get
|
match "/geocoder/search_uk_postcode" => "geocoder#search_uk_postcode", :via => :get
|
||||||
match "/geocoder/search_ca_postcode" => "geocoder#search_ca_postcode", :via => :get
|
match "/geocoder/search_ca_postcode" => "geocoder#search_ca_postcode", :via => :get
|
||||||
match "/geocoder/search_osm_nominatim" => "geocoder#search_osm_nominatim", :via => :get
|
match "/geocoder/search_osm_nominatim" => "geocoder#search_osm_nominatim", :via => :get
|
||||||
|
|
|
@ -15,10 +15,6 @@ class GeocoderControllerTest < ActionController::TestCase
|
||||||
{ :path => "/geocoder/search_latlon", :method => :get },
|
{ :path => "/geocoder/search_latlon", :method => :get },
|
||||||
{ :controller => "geocoder", :action => "search_latlon" }
|
{ :controller => "geocoder", :action => "search_latlon" }
|
||||||
)
|
)
|
||||||
assert_routing(
|
|
||||||
{ :path => "/geocoder/search_us_postcode", :method => :get },
|
|
||||||
{ :controller => "geocoder", :action => "search_us_postcode" }
|
|
||||||
)
|
|
||||||
assert_routing(
|
assert_routing(
|
||||||
{ :path => "/geocoder/search_uk_postcode", :method => :get },
|
{ :path => "/geocoder/search_uk_postcode", :method => :get },
|
||||||
{ :controller => "geocoder", :action => "search_uk_postcode" }
|
{ :controller => "geocoder", :action => "search_uk_postcode" }
|
||||||
|
@ -253,7 +249,7 @@ class GeocoderControllerTest < ActionController::TestCase
|
||||||
].each do |code|
|
].each do |code|
|
||||||
post :search, :params => { :query => code }
|
post :search, :params => { :query => code }
|
||||||
assert_response :success
|
assert_response :success
|
||||||
assert_equal %w[us_postcode osm_nominatim], assigns(:sources)
|
assert_equal %w[osm_nominatim], assigns(:sources)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -304,25 +300,6 @@ class GeocoderControllerTest < ActionController::TestCase
|
||||||
results_check_error "Longitude 180.23 out of range"
|
results_check_error "Longitude 180.23 out of range"
|
||||||
end
|
end
|
||||||
|
|
||||||
##
|
|
||||||
# Test the US postcode search
|
|
||||||
def test_search_us_postcode
|
|
||||||
with_http_stubs "geocoder_us" do
|
|
||||||
get :search_us_postcode, :xhr => true,
|
|
||||||
:params => { :query => "90210", :zoom => 10,
|
|
||||||
:minlon => -0.559, :minlat => 51.217,
|
|
||||||
:maxlon => 0.836, :maxlat => 51.766 }
|
|
||||||
results_check :prefix => "Beverly Hills, CA,", :name => "90210",
|
|
||||||
:lat => 34.088808, :lon => -118.40612
|
|
||||||
|
|
||||||
get :search_us_postcode, :xhr => true,
|
|
||||||
:params => { :query => "00000", :zoom => 10,
|
|
||||||
:minlon => -0.559, :minlat => 51.217,
|
|
||||||
:maxlon => 0.836, :maxlat => 51.766 }
|
|
||||||
results_check
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
##
|
##
|
||||||
# Test the UK postcode search
|
# Test the UK postcode search
|
||||||
def test_search_uk_postcode
|
def test_search_uk_postcode
|
||||||
|
|
|
@ -1,6 +0,0 @@
|
||||||
/service/csv?zip=90210:
|
|
||||||
code: 200
|
|
||||||
body: "34.088808, -118.40612, Beverly Hills, CA, 90210"
|
|
||||||
/service/csv?zip=00000:
|
|
||||||
code: 200
|
|
||||||
body: "1: couldn't find this zip code: 00000! sorry"
|
|
Loading…
Add table
Add a link
Reference in a new issue