# Google Map

**URL:** <https://www.ruby-forum.com/t/google-map/94968>\
**Category:** Rails\
**Created:** [May 18, 2006, 11:45am UTC](https://www.ruby-forum.com/t/google-map/94968 "2006-05-18T11:45:02Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![robtotheb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/db5fbb/32.png) [@robtotheb](https://www.ruby-forum.com/u/robtotheb)\
**Post date:** [May 18, 2006, 11:45am UTC](https://www.ruby-forum.com/t/google-map/94968/1 "2006-05-18T11:45:02Z")

</div>

Used a great howto @

[http://iamrice.org/articles/2005/12/09/using-google-maps-in-the-uk-with-rails](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

---

<div class="post-metadata">

**Author:** ![robtotheb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/db5fbb/32.png) [@robtotheb](https://www.ruby-forum.com/u/robtotheb)\
**Post date:** [May 18, 2006, 5:13pm UTC](https://www.ruby-forum.com/t/google-map/94968/2 "2006-05-18T17:13:44Z")

</div>

Rob B. wrote:

> require ‘postcode\_2\_latlong’

Uh huh.

> Then postcode.rb in /lib reads…

Ahh.

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,

Tom

---

<div class="post-metadata">

**Author:** ![robtotheb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/db5fbb/32.png) [@robtotheb](https://www.ruby-forum.com/u/robtotheb)\
**Post date:** [May 18, 2006, 5:46pm UTC](https://www.ruby-forum.com/t/google-map/94968/3 "2006-05-18T17:46:37Z")

</div>

I’m using a very similar piece of code that I wrote myself, except I’m  
getting it here:

> **[SamKnows](https://www.samknows.com/toys/coords.php?output=xml&pc=se270nb)**
>
> Internet performance monitoring

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:

> **[SamKnows](https://www.samknows.com/toys/coords.php?output=xml&pc=se270nb,sw47ln,so416et,w126aa)**
>
> Internet performance monitoring

Valid outputs are xml, csv and php.

-Nathan

---

<div class="post-metadata">

**Author:** ![robtotheb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/db5fbb/32.png) [@robtotheb](https://www.ruby-forum.com/u/robtotheb)\
**Post date:** [May 19, 2006, 5:47pm UTC](https://www.ruby-forum.com/t/google-map/94968/4 "2006-05-19T17:47:35Z")

</div>

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:
> 
> [Page not found | SamKnows](http://www.samknows.com/toys/coords.php?output=xml&pc=se270nb)

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

Thanks a lot,

Tom
