diff --git a/README.rdoc b/README.rdoc index 7b31c0346800d39a54592111974cb8a61dd5cd97..e39f071722660a8ccc32f2e7f51341cb5567d0d6 100644 --- a/README.rdoc +++ b/README.rdoc @@ -163,6 +163,15 @@ You can set the timeout used for connections to the geocoding service. The defau # config/initializers/geocoder.rb Geocoder::Configuration.timeout = 5 +=== Language + +You can set the language used for reverse geocoding results to German, for example, by setting the following: + + # config/initializers/geocoder.rb + Geocoder::Configuration.language = :de + +For a list of supported languages see the documentation for the geocoding service you're using. + == Forward and Reverse Geocoding in the Same Model diff --git a/lib/geocoder/configuration.rb b/lib/geocoder/configuration.rb index b5c2edf1758397ceb05cee80c0760aedbe7b9c59..795881904d5bf1aafa36f4f9a1a3a49cf92c2c9c 100644 --- a/lib/geocoder/configuration.rb +++ b/lib/geocoder/configuration.rb @@ -1,11 +1,19 @@ module Geocoder class Configuration + + # geocoding service timeout (secs) def self.timeout; @@timeout; end def self.timeout=(obj); @@timeout = obj; end + # name of geocoding service (symbol) def self.lookup; @@lookup; end def self.lookup=(obj); @@lookup = obj; end + # ISO-639 language code + def self.language; @@language; end + def self.language=(obj); @@language = obj; end + + # app id (if using Yahoo geocoding service) def self.yahoo_appid; @@yahoo_appid; end def self.yahoo_appid=(obj); @@yahoo_appid = obj; end end @@ -13,4 +21,5 @@ end Geocoder::Configuration.timeout = 3 Geocoder::Configuration.lookup = :google +Geocoder::Configuration.language = :en Geocoder::Configuration.yahoo_appid = "" diff --git a/lib/geocoder/lookups/google.rb b/lib/geocoder/lookups/google.rb index 87f56d8f6456eb3027ca1e61452fde256f06d922..3f7144cf8ccefa5de5e5c195f7a0ce15ffa5b4a9 100644 --- a/lib/geocoder/lookups/google.rb +++ b/lib/geocoder/lookups/google.rb @@ -22,7 +22,8 @@ module Geocoder::Lookup def query_url(query, reverse = false) params = { (reverse ? :latlng : :address) => query, - :sensor => "false" + :sensor => "false", + :language => Geocoder::Configuration.language } "http://maps.google.com/maps/api/geocode/json?" + hash_to_query(params) end diff --git a/lib/geocoder/lookups/yahoo.rb b/lib/geocoder/lookups/yahoo.rb index dc831c68e01158d2997b10e7cdd046799dfcd0d3..c0ba9d19ff63fd680348d928623ae380f5513c41 100644 --- a/lib/geocoder/lookups/yahoo.rb +++ b/lib/geocoder/lookups/yahoo.rb @@ -20,6 +20,7 @@ module Geocoder::Lookup :location => query, :flags => "JXTSR", :gflags => "AC#{'R' if reverse}", + :locale => "#{Geocoder::Configuration.language}_US", :appid => Geocoder::Configuration.yahoo_appid } "http://where.yahooapis.com/geocode?" + hash_to_query(params)