diff --git a/lib/geocoder/lookups/base.rb b/lib/geocoder/lookups/base.rb
index e4b792efe9bab4d11b0e73119aaafba0e0160888..92884cc95a2cddf1d9a55196e2cac07a1f60942d 100644
--- a/lib/geocoder/lookups/base.rb
+++ b/lib/geocoder/lookups/base.rb
@@ -88,6 +88,14 @@ module Geocoder
           Net::HTTP.get_response(URI.parse(url)).body
         end
       end
+
+      ##
+      # Simulate ActiveSupport's Object#to_query.
+      #
+      def hash_to_query(hash)
+        require 'cgi' unless defined?(CGI) && defined?(CGI.escape)
+        hash.collect{ |p| p.map{ |i| CGI.escape i.to_s } * '=' }.sort * '&'
+      end
     end
   end
 end
diff --git a/lib/geocoder/lookups/google.rb b/lib/geocoder/lookups/google.rb
index 61757a0bf04d9bc910b1663086239568616eec24..52f87238555b56f17b87b66bbc9485a65f389552 100644
--- a/lib/geocoder/lookups/google.rb
+++ b/lib/geocoder/lookups/google.rb
@@ -24,7 +24,7 @@ module Geocoder::Lookup
         (reverse ? :latlng : :address) => query,
         :sensor => "false"
       }
-      "http://maps.google.com/maps/api/geocode/json?" + params.to_query
+      "http://maps.google.com/maps/api/geocode/json?" + hash_to_query(params)
     end
   end
 end
diff --git a/lib/geocoder/lookups/yahoo.rb b/lib/geocoder/lookups/yahoo.rb
index 752e8760b3047c15ea4350091bd4dfcd1e08142b..efab5c84f74b95d5183bf22a424ddf6778846acd 100644
--- a/lib/geocoder/lookups/yahoo.rb
+++ b/lib/geocoder/lookups/yahoo.rb
@@ -22,7 +22,7 @@ module Geocoder::Lookup
         :gflags => "AC#{'R' if reverse}",
         :appid => Geocoder::Configuration.yahoo_appid
       }
-      "http://where.yahooapis.com/geocode?" + params.to_query
+      "http://where.yahooapis.com/geocode?" + hash_to_query(params)
     end
   end
 end
diff --git a/test/geocoder_test.rb b/test/geocoder_test.rb
index a0a9ab679c28f047f69ef5f03859a2449e87e781..a625e79c8ab852e499e42eef2631e695d1543685 100644
--- a/test/geocoder_test.rb
+++ b/test/geocoder_test.rb
@@ -110,6 +110,11 @@ class GeocoderTest < Test::Unit::TestCase
     assert !Geocoder.send(:blank_query?, "a")
   end
 
+  def test_hash_to_query
+    g = Geocoder::Lookup::Google.new
+    assert_equal "a=1&b=2", g.send(:hash_to_query, {:a => 1, :b => 2})
+  end
+
 
   private # ------------------------------------------------------------------