Skip to content

Commit

Permalink
Plugin Configuration for Multi-ip Geocoders, and MaxMind City.
Browse files Browse the repository at this point in the history
Signed-off-by: Andre Lewis <andre.lewis@gmail.com>
  • Loading branch information
dreamcat4 authored and andre committed May 13, 2009
1 parent f5afe49 commit 13114e8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
19 changes: 17 additions & 2 deletions assets/api_keys_template
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,14 @@ if defined? Geokit
# See http://geocoder.ca
# and http://geocoder.ca/?register=1
Geokit::Geocoders::geocoder_ca = false


# This is your authorization key for MaxMind's geoip city web service.
# Paid alternative to the free hostip.info ip Geocoder
# See http://www.maxmind.com/app/web_services#country
# Set the value to the 12-digit key obtained from MaxMind.
# Geokit::Geocoders::maxmind_city = 'REPLACE_WITH_YOUR_MAXMIND_KEY'
Geokit::Geocoders::maxmind_city = '2AbwX9KUFnFh'

# Uncomment to use a username with the Geonames geocoder
#Geokit::Geocoders::geonames="REPLACE_WITH_YOUR_GEONAMES_USERNAME"

Expand All @@ -52,5 +59,13 @@ if defined? Geokit
# Be aware that there are Terms of Use restrictions on how you can use the
# various geocoders. Make sure you read up on relevant Terms of Use for each
# geocoder you are going to use.
Geokit::Geocoders::provider_order = [:google,:us]
Geokit::Geocoders::provider_order = [:yahoo,:google]

# Valid symbols are :ip,:geonames,:geo_plugin, and :maxmind_city.
# As before, make sure you read up on relevant Terms of Use for each
# Geokit::Geocoders::ip_provider_order = [:geo_plugin,:ip]
Geokit::Geocoders::ip_provider_order = [:maxmind_city,:geo_plugin,:ip]
# Geokit::Geocoders::ip_provider_order = [:maxmind_city]

end

13 changes: 10 additions & 3 deletions lib/geokit-rails/ip_geocode_lookup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,22 @@ def geocode_ip_address(filter_options = {})
# get the value.
def store_ip_location
session[:geo_location] ||= retrieve_location_from_cookie_or_service
cookies[:geo_location] = { :value => session[:geo_location].to_yaml, :expires => 30.days.from_now } if session[:geo_location]
cookies[:geo_location] = { :value => session[:geo_location].to_yaml, :expires => 0.days.from_now } if session[:geo_location]
end

# Uses the stored location value from the cookie if it exists. If
# no cookie exists, calls out to the web service to get the location.
def retrieve_location_from_cookie_or_service
return YAML.load(cookies[:geo_location]) if cookies[:geo_location]
location = Geocoders::IpGeocoder.geocode(get_ip_address)
return location.success ? location : nil
# location = Geocoders::IpGeocoder.geocode(get_ip_address)
# location = Geocoders::GeoPluginGeocoder.geocode(get_ip_address)
# location = Geocoders::MaxmindCityGeocoder.geocode(get_ip_address)
location = Geocoders::MultiIpGeocoder.do_geocode(get_ip_address)
# result = location.success ? location : GeoLoc.new
# result.all = nil
# return location.success ? location : GeoLoc.new
return location
# return result
end

# Returns the real ip address, though this could be the localhost ip
Expand Down

0 comments on commit 13114e8

Please sign in to comment.