Coder Social home page Coder Social logo

lab-geo-api's Introduction

lab-geo-api

This is a lab project - use at your own risk! =^-^=

In brief, lab-geo-api is a nodejs express api that lets your lookup cities' geo data in a database filled with maxmind's free ip data. It is probably far from usable in any real business application but you are free to use the code and play around with it.

howto

Download the maxmind db (csv) and load it into a database of your choice. I use mysql server, so use that if you wish to use the code as-is.

http://dev.maxmind.com/geoip/legacy/geolite/

Create a table and load the csv, see the code examples below.

db

The following scripts reflect how I use the data - you may want to do things in a different way.

First, create an import table and a locations table.

CREATE TABLE `maxmind`.`import` (
  `locId` INT NULL,
  `country` VARCHAR(100) NULL,
  `region` VARCHAR(45) NULL,
  `city` VARCHAR(45) NULL,
  `postalCode` VARCHAR(45) NULL,
  `latitude` FLOAT NULL,
  `longitude` FLOAT NULL,
  `metroCode` VARCHAR(45) NULL,
  `areaCode` VARCHAR(45) NULL);
CREATE TABLE `maxmind`.`locations` (
  `city` VARCHAR(45) NULL,
  `latitude` FLOAT NULL,
  `longitude` FLOAT NULL);

Load the maxmind data from the csv. Note the path and the character set here, change them to suit your environment.

load data infile '/home/ilix/geo/GeoLiteCity_20140401/GeoLiteCity-Location.csv' into table import character set latin1 fields terminated by ',' enclosed by '"';

Copy the data you actually want to use to the locations table.

truncate table `locations`;
insert into `locations` select distinct city, latitude, longitude from `import` where country = 'SE';

Finally, you can truncate or drop the import table if you wish to save space.

config

Create a file called app.config.json where app.js is.

{
  "db": {
    "host": "127.0.0.1",
    "port": 3306,
    "password": "iHasSikrit",
    "username": "meow"
  }
}

lab-geo-api's People

Watchers

James Cloos 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.