Permalink
Browse files

Adds unicode compliance for URL escaping and Net:HTTP fetching for Go…

…ogle Geocode
  • Loading branch information...
evenwestvang committed Oct 16, 2010
1 parent b67a046 commit 0d70f0e74d6d7db0644274426f6c83c1d6874400
Showing with 2 additions and 3 deletions.
  1. +2 −3 lib/geokit/geocoders.rb
View
@@ -37,9 +37,7 @@ def snake_case(s)
end
def url_escape(s)
- s.gsub(/([^ a-zA-Z0-9_.-]+)/nu) do
- '%' + $1.unpack('H2' * $1.size).join('%').upcase
- end.tr(' ', '+')
+ CGI.escape(s)
end
def camelize(str)
@@ -433,6 +431,7 @@ def self.do_geocode(address, options = {})
res = self.call_geocoder_service("http://maps.google.com/maps/geo?q=#{Geokit::Inflector::url_escape(address_str)}&output=xml#{bias_str}&key=#{Geokit::Geocoders::google}&oe=utf-8")
return GeoLoc.new if !res.is_a?(Net::HTTPSuccess)
xml = res.body
+ xml = xml.force_encoding(Encoding::UTF_8)
logger.debug "Google geocoding. Address: #{address}. Result: #{xml}"
return self.xml2GeoLoc(xml, address)
end

0 comments on commit 0d70f0e

Please sign in to comment.