Used a great howto @
http://iamrice.org/articles/2005/12/09/using-google-maps-in-the-uk-with-rails
for using google maps on uk sites. Just having one issue I can’t seem
to work out how to draw the postcode from my table I keep getting hit by
method errors.
The controller is
require ‘postcode_2_latlong’
postcode = Postcode.new(“TN22 2LG”)
I want this to be a postcode from my database not TN22…
latlong = postcode.to_latlong
Then postcode.rb in /lib reads…
require ‘uri’
require ‘open-uri’
class Postcode
def initialize(postcode)
@postcode = postcode
end
def to_latlong
#postcode = URI.escape(@postcode)
postcode = @postcode.gsub(/ /, “+”)
postcode2 = @postcode.gsub(/ /, “”)
#open("http://maps.google.com/maps?q=#{postcode}") do |f|
open("http://multimap.com/map/browse.cgi?client=public&search_result=&db=pc&cidr_client=none&lang=&keepicon=true&pc=#{postcode2}&advanced=&client=public&addr2=&quicksearch=#{postcode}")
do |f|
#coords = f.read.match(/lat="(-?\d+.\d+)"
lng="(-?\d+.\d+)"/)
ret_html = f.read
coord_lat = ret_html.match(/<dd class="latitude">\d+:\d+:\d+\w
((-?\d+.\d+))/)
coord_lon = ret_html.match(/<dd class="longitude">\d+:\d+:\d+\w
((-?\d+.\d+))/)
unless coord_lat.nil? and coord_lon.nil?
return { :lat => coord_lat.to_a[1], :long => coord_lon.to_a[1] }
else
return nil
end
end
end
end