0.04
No release in over 3 years
Low commit activity in last 3 years
Geo Location allows you to geo-locate your users using their IP address via hostip.info or maxmind.com. This Ruby gem is dead simple to use and configure. Checkout the README and post any issue (or pull requests) to us on GitHub.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

 Project Readme

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

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: 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.