Skip to content

Instantly share code, notes, and snippets.

@ubermajestix
Created April 25, 2009 21:19
Show Gist options
  • Save ubermajestix/101755 to your computer and use it in GitHub Desktop.
Save ubermajestix/101755 to your computer and use it in GitHub Desktop.
require 'nokogiri'
require 'open-uri'
def geocode(address_str)
# html escape address_str
res = Nokogiri::XML(open("http://maps.google.com/maps/geo?q=#{address_str}&output=xml&key=&oe=utf-8"))
status = res.search("code").inner_html
coords = res.search("coordinates").inner_html.split(",")[0,2] if status == "200"
coords << res.search("address").inner_html if status == "200"
return coords
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment