Created
March 10, 2011 04:16
-
-
Save n3bulous/863567 to your computer and use it in GitHub Desktop.
monkey patching geokit to support google premier
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
# Monkey Patch to enable google premier | |
module Geokit | |
module Geocoders | |
@@google_client_id = nil | |
__define_accessors | |
class GoogleGeocoder | |
private | |
def self.do_geocode(address, options = {}) | |
bias_str = options[:bias] ? construct_bias_string_from_options(options[:bias]) : '' | |
address_str = address.is_a?(GeoLoc) ? address.to_geocodeable_s : address | |
request = "http://maps.google.com/maps/geo?q=#{Geokit::Inflector::url_escape(address_str)}&output=xml#{bias_str}&oe=utf-8" | |
if (Geokit::Geocoders::google_client_id.blank?) | |
request << "&key=" << Geokit::Geocoders::google | |
else | |
request << "&client=" << Geokit::Geocoders::google_client_id | |
request << "&sensor=false" | |
end | |
res = self.call_geocoder_service(request) | |
return GeoLoc.new if !res.is_a?(Net::HTTPSuccess) | |
xml = res.body | |
logger.debug "Google geocoding. Address: #{address}. Result: #{xml}" | |
return self.xml2GeoLoc(xml, address) | |
end | |
end # class GoogleGeocoder | |
end # module Geocoders | |
end # module Geokit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment