Skip to content

Geo-locate your users using their IP address via hostip.info (free) or maxmind.com (paid) with the Rails 3 GeoLocation gem.

License

Notifications You must be signed in to change notification settings

cameronhickey/geo_location

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 www.maxmind.com/app/city and for more information about HostIP visit hostip.info

Installation

gem install 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: 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 © 2010 Chris Your. See LICENSE for details.

About

Geo-locate your users using their IP address via hostip.info (free) or maxmind.com (paid) with the Rails 3 GeoLocation gem.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Ruby 100.0%