Skip to content

Instantly share code, notes, and snippets.

@tomharris
Created December 5, 2008 20:21
Show Gist options
  • Save tomharris/32495 to your computer and use it in GitHub Desktop.
Save tomharris/32495 to your computer and use it in GitHub Desktop.
require "net/http"
require "uri"
module Google
class Geocode
attr_accessor :address
attr_reader :key, :latutude, :longitude
def initialize( key, address )
@key = key
@address = address
end
def lookup
uri = URI.parse( "http://maps.google.com/maps/geo?sensor=false&output=csv&q=#{CGI.escape(@address)}&key=#{@key}" )
res = Net::HTTP.get_response( uri )
case res
when Net::HTTPSuccess
#set lat, long
status, accuracy, latutude, longitude = res.body.split( ',' )
if status == "200"
@latutude = latutude
@longitude = longitude
else
RAILS_DEFAULT_LOGGER.debug res.body
res.error!
end
else
RAILS_DEFAULT_LOGGER.debug res.body
res.error!
end
self
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment