From a4f4714d0e1b1eeabe5e4b411800b949ef1e1139 Mon Sep 17 00:00:00 2001 From: Nick Black Date: Tue, 1 May 2007 13:26:27 +0000 Subject: [PATCH] added a marker to show a location on the map --- app/controllers/geocoder_controller.rb | 12 +++--- app/views/geocoder/results.rhtml | 2 +- app/views/site/index.rhtml | 60 +++++++++++++++++++------- 3 files changed, 52 insertions(+), 22 deletions(-) diff --git a/app/controllers/geocoder_controller.rb b/app/controllers/geocoder_controller.rb index 6955579ed..8f0f80441 100644 --- a/app/controllers/geocoder_controller.rb +++ b/app/controllers/geocoder_controller.rb @@ -23,7 +23,7 @@ class GeocoderController < ApplicationController data = resp.body.split(/, /) # lat,long,town,state,zip lat = data[0] lon = data[1] - redirect_to "/index.html?lat=#{lat}&lon=#{lon}&zoom=14" + redirect_to "/index.html?mlat=#{lat}&mlon=#{lon}&zoom=14" return end elsif postcode.match(/^([A-Z]{1,2}\d+[A-Z]?\s*\d[A-Z]{2})/) @@ -35,7 +35,7 @@ class GeocoderController < ApplicationController data = dataline.split(/,/) # easting,northing,postcode,lat,long lat = data[3] lon = data[4] - redirect_to "/index.html?lat=#{lat}&lon=#{lon}&zoom=14" + redirect_to "/index.html?mlat=#{lat}&mlon=#{lon}&zoom=14" return end elsif postcode.match(/^[A-Z]\d[A-Z]\s*\d[A-Z]\d/) @@ -48,7 +48,7 @@ class GeocoderController < ApplicationController data_lon = resp.body.slice(/longt>.*?]/)[1] lon = data_lon.split(/[<>]/)[1] - redirect_to "/index.html?lat=#{lat}&lon=#{lon}&zoom=14" + redirect_to "/index.html?mlat=#{lat}&mlon=#{lon}&zoom=14" return end elsif postcode.match(/(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]) [0-9][ABD-HJLNP-UW-Z]{2}) @@ -59,14 +59,14 @@ class GeocoderController < ApplicationController resp = http.get("/geocode?postcode=#{postcode}") lat = resp.body.scan(/[4-6][0-9]\.?[0-9]+/) lon = resp.body.scan(/[-+][0-9]\.?[0-9]+/) - redirect_to "/index.html?lat=#{lat}&lon=#{lon}&zoom=14" + redirect_to "/index.html?mlat=#{lat}&mlon=#{lon}&zoom=14" return end rescue redirect_to "/index.html" #redirect to somewhere else end - redirect_to "/index.html?lat=#{lat}&lon=#{lon}&zoom=14" + redirect_to "/index.html?mlat=#{lat}&mlon=#{lon}&zoom=14" #redirect_to "/index.html?error=unknown_postcode_or_zip" elsif # Some other postcode / zip code @@ -83,7 +83,7 @@ class GeocoderController < ApplicationController data_lon = resp.body.slice(/lng>.*?]/)[1] lon = data_lon.split(/[<>]/)[1] - redirect_to "/index.html?lat=#{lat}&lon=#{lon}&zoom=14" + redirect_to "/index.html?mlat=#{lat}&mlon=#{lon}&zoom=14" end else # Some other postcode / zip file diff --git a/app/views/geocoder/results.rhtml b/app/views/geocoder/results.rhtml index 3d7ee9060..e4a48dd18 100644 --- a/app/views/geocoder/results.rhtml +++ b/app/views/geocoder/results.rhtml @@ -18,7 +18,7 @@ <%= hsh['countryname'] %> -<%= link_to('Map', url="/index.html?lat=#{hsh['lat']}&lon=#{hsh['lon']}&zoom=12") %> +<%= link_to('Map', url="/index.html?mlat=#{hsh['lat']}&mlon=#{hsh['lon']}&zoom=12") %> <%= link_to('API', url="/#FIXME") %> diff --git a/app/views/site/index.rhtml b/app/views/site/index.rhtml index 7c1c083b7..bed35e36f 100644 --- a/app/views/site/index.rhtml +++ b/app/views/site/index.rhtml @@ -7,20 +7,31 @@ <%= submit_tag 'Search' %> <%= end_form_tag %> -
- Geolocation provided by npemap.org.uk, - geocoder.us, geocoder.ca - and geonames.org -
-
-eg: SW15 6JH, 95472 or H2L4C1 -
-
-eg:Essen -
+
+ Geolocation provided by npemap.org.uk, + geocoder.us, geocoder.ca + and geonames.org +
+
+ eg: SW15 6JH, 95472 or H2L4C1 +
+
+ eg:Essen +
-<% if @user and params['lon'].nil? and params['lat'].nil? %> +<% if params['mlon'] and params['mlat'] %> +<% marker = true %> +<% mlon = params['mlon'] %> +<% mlat = params['mlat'] %> +<% lon = params['mlon'] %> +<% lat = params['mlat'] %> +<% zoom = params['zoom'] || '12' %> + +<% elsif @user and params['lon'].nil? and params['lat'].nil? %> <% lon = @user.home_lon %> <% lat = @user.home_lat %> <% zoom = '10' %> @@ -30,12 +41,16 @@ eg:Essen <% zoom = params['zoom'] || '4' %> <% end %> + +