# Lookup on Google Maps

**URL:** <https://www.ruby-forum.com/t/lookup-on-google-maps/113099>\
**Category:** Rails\
**Created:** [August 27, 2007, 5:13pm UTC](https://www.ruby-forum.com/t/lookup-on-google-maps/113099 "2007-08-27T17:13:01Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jandot](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/439d5e/32.png) [@jandot](https://www.ruby-forum.com/u/jandot)\
**Post date:** [August 27, 2007, 5:13pm UTC](https://www.ruby-forum.com/t/lookup-on-google-maps/113099/1 "2007-08-27T17:13:01Z")

</div>

I have a table of address in my database. I want to show these on a  
google map. The problem is, I can only get it to work if I have a pretty  
geocode like this: ‘555 Irving, San Francisco, CA’,Irving’ and my data  
is not compatible with this format, as it formatted like this: “Tsukuba,  
Japan”.

How can I look up an address like “Tsukuba, Japan”, and get a geocode I  
can use for a Google Maps lookup?

My code for looking up places so far looks like this (I had to hardcode  
“places” to get it to work)

def show

```
places = [
        {:address=>'555 Irving, San Francisco,

```

CA’,:description=\>‘Irving’}  
]  
# this loop will do the geo lookup for each place  
places.each do |place|  
# get the geocode by calling our own get\_geocode(address) method  
place.merge! get\_geocode(place[:address])

```
  end

  #place the result in the session so we can use it for display
  session[:places] = places

end

def show_google_map
  # all we're going to do is loop through the @places array on the

```

page  
@places=session[:places]  
end

```
private
def get_geocode(address)
  logger.debug 'starting geocoder call for address: '+address
  # this is where we call the geocoding web service
  server =

```

XMLRPC::Client.new2(‘[http://rpc.geocoder.us/service/xmlrpc](http://rpc.geocoder.us/service/xmlrpc)’)  
result = server.call2(‘geocode’, address)  
logger.debug "Geocode call: "+result.inspect

```
  return {:success=> true, :latitude=> result[1][0]['lat'],
  :longitude=> result[1][0]['long']}
end

```

---

<div class="post-metadata">

**Author:** ![jandot](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/439d5e/32.png) [@jandot](https://www.ruby-forum.com/u/jandot)\
**Post date:** [August 28, 2007, 5:36am UTC](https://www.ruby-forum.com/t/lookup-on-google-maps/113099/2 "2007-08-28T05:36:57Z")

</div>

Have a look at the geokit plugin for Rails. I’ve used it and it will  
parse address like the one you’ve given.  
I’ve used it for something similar and worked a treat.  
[http://geokit.rubyforge.org/](http://geokit.rubyforge.org/)

(PS google recommends that your store the lat,lng co-ordinates in your  
database, rather than slamming their geocoder everytime you make a  
request)

Cheers, Cam
