Created
December 5, 2008 20:21
-
-
Save tomharris/32495 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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