Lookup on Google Maps

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,

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,

# 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])


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


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


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

result = server.call2(‘geocode’, address)
logger.debug "Geocode call: "+result.inspect

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

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.

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

Cheers, Cam

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs