Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Simple IP to lat/long API application using the MaxMind GeoLite database.

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 ext
Octocat-spinner-32 vendor
Octocat-spinner-32 .gitignore
Octocat-spinner-32 .rvmrc
Octocat-spinner-32 Isolate
Octocat-spinner-32 README.md
Octocat-spinner-32 app.rb
Octocat-spinner-32 config.ru
Octocat-spinner-32 init.rb
README.md

Sinatra GeoIP App

Extremely simple IP to Lat/Long API demo. Use at your own risk.

Author

Geoffrey Grosenbach http://peepcode.com

Requirements

  • Build ext/GeoIP-1.4.6 (./configure && make && sudo make install)
  • Download binary GeoLiteCity.dat database from http://www.maxmind.com/app/geolitecity
  • Put GeoLiteCity.dat in "./data"
  • Isolate will install other dependencies when you launch the app.

Run

rackup -p 3000 config.ru

API

View JSON data for an IP address with:

http://localhost:3000/geoip/api/locate.json?ip=24.18.211.123

{
    latitude: 47.684700012207
    country_name: "United States"
    area_code: 206
    city: "Seattle"
    region: "WA"
    longitude: -122.384803771973
    postal_code: "98117"
    country_code3: "USA"
    country_code: "US"
    dma_code: 819
}

Legal

This product includes GeoLite data created by MaxMind, available from http://www.maxmind.com/.

Something went wrong with that request. Please try again.