From b5c8ccf185d5826619addbfc8a5475e60be42376 Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Sun, 13 Mar 2011 16:57:39 -0400 Subject: [PATCH] Add result language configuration. --- README.rdoc | 9 +++++++++ lib/geocoder/configuration.rb | 9 +++++++++ lib/geocoder/lookups/google.rb | 3 ++- lib/geocoder/lookups/yahoo.rb | 1 + 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/README.rdoc b/README.rdoc index 7b31c034..e39f0717 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 b5c2edf1..79588190 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 87f56d8f..3f7144cf 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 dc831c68..c0ba9d19 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) -- GitLab