Giter Site home page Giter Site logo

stipple / geo_location Goto Github PK

View Code? Open in Web Editor NEW

This project forked from chrisyour/geo_location

2.0 1.0 0.0 256 KB

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

License: MIT License

Ruby 100.00%

geo_location's Introduction

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.

geo_location's People

Contributors

chrisyour avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.