Forum: Ruby on Rails Google Map

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Rob B. (Guest)
on 2006-05-18 13:45
Used a great howto @

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 ="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

  def to_latlong
    #postcode = URI.escape(@postcode)
    postcode = @postcode.gsub(/ /, "+")
    postcode2 = @postcode.gsub(/ /, "")

    #open("{postcode}") do |f|
do |f|
      #coords =\"(-?\d+\.\d+)\"
      ret_html =
      coord_lat = ret_html.match(/<dd class=\"latitude\">\d+:\d+:\d+\w
      coord_lon = ret_html.match(/<dd class=\"longitude\">\d+:\d+:\d+\w
      unless coord_lat.nil? and coord_lon.nil?
        return { :lat => coord_lat.to_a[1], :long => coord_lon.to_a[1] }
        return nil
Tom T. (Guest)
on 2006-05-18 19:13
(Received via mailing list)
Rob B. wrote:
> require 'postcode_2_latlong'

Uh huh.

> Then postcode.rb in /lib reads...


Change require to 'postcode', and it'll look for the correct file.

It looks like an awesomely useful piece of code - I'm sure I'll use it
for my next project!

Good luck,

unknown (Guest)
on 2006-05-18 19:46
(Received via mailing list)
I'm using a very similar piece of code that I wrote myself, except I'm
getting it here:

It'll be much faster loading that little bit of code than the massive
amounts that multimap like to send. And, you can get more than one
postcode like so:

Valid outputs are xml, csv and php.

Tom T. (Guest)
on 2006-05-19 19:47
(Received via mailing list)
removed_email_address@domain.invalid wrote:
> I'm using a very similar piece of code that I wrote myself, except I'm
> getting it here:

Looks awesome. Can you make it available somewhere? Saves reinventing
the wheel!

Thanks a lot,

This topic is locked and can not be replied to.