geo_location
geo_location copied to clipboard
Geo-locate your users using their IP address via hostip.info (free) or maxmind.com (paid) with the Rails 3 GeoLocation gem.
= Geo Location
Easily geo-locate your users using their IP address via hostip.info or maxmind.com. Super simple to setup, super simple to use. I've found that the data from HostIP and Max Mind differ slightly. Max Mind (paid) has a more complete and accurate database at the moment, but HostIP is growing. For more information about Max Mind visit http://www.maxmind.com/app/city and for more information about HostIP visit http://hostip.info
== Installation
gem install geo_location
== Gemspec (using Bundler) Add geo_location to your Gemspec.
gem 'geo_location'
== HostIP Configuration
config/initializers/geo_location_config.rb:
unless GeoLocation == nil # Use Hostip (free) GeoLocation::use = :hostip end
== HostIP Example
location = GeoLocation.find('24.24.24.24') # => {:ip=>"24.24.24.24", :city=>"Liverpool", :region=>"NY", :country=>"United States", :country_code=>"US", :latitude=>"43.1059", :longitude=>"-76.2099", :timezone=>"America/New_York"}
puts location[:ip] # => 24.24.24.24 puts location[:city] # => Liverpool puts location[:region] # => NY puts location[:country] # => United States puts location[:country_code] # => US puts location[:latitude] # => 43.1059 puts location[:longitude] # => -76.2099 puts location[:timezone] # => America/New_York
== Max Mind Configuration
config/initializers/geo_location_config.rb:
unless GeoLocation == nil # Use Max Mind (paid) # For more information visit: http://www.maxmind.com/app/city GeoLocation::use = :maxmind GeoLocation::key = 'YOUR MaxMind.COM LICENSE KEY' # This location will be used while you develop rather than hitting the maxmind.com api # GeoLocation::dev = 'US,NY,Jamaica,40.676300,-73.775200' # IP: 24.24.24.24 # Use this IP in development mode (development and testing will give you 127.0.0.1) # GeoLocation::dev_ip = '24.24.24.24' end
== Max Mind Example
GeoLocation::use = :maxmind GeoLocation::key = 'YOUR MaxMind.COM LICENSE KEY' location = GeoLocation.find('24.24.24.24') # => {:ip=>"24.24.24.24", :city=>"Jamaica", :region=>"NY", :country=>"United States", :country_code=>"US", :latitude=>"40.676300", :longitude=>"-73.775200", :timezone=>"America/New_York"}
puts location[:ip] # => 24.24.24.24 puts location[:city] # => Jamaica puts location[:region] # => NY puts location[:country] # => United States puts location[:country_code] # => US puts location[:latitude] # => 40.676300 puts location[:longitude] # => -73.775200 puts location[:timezone] # => America/New_York
== Copyright
Copyright (c) 2010 Chris Your. See LICENSE for details.