Skip to content
Browse files

examples

  • Loading branch information...
1 parent f7e6bf8 commit f175e4c97e35be3b5caae34c6cca9e022539ec27 @runk committed Mar 9, 2013
Showing with 62 additions and 7 deletions.
  1. +13 −3 README.md
  2. +16 −0 examples/city.js
  3. +8 −0 examples/country.js
  4. +10 −0 examples/distance.js
  5. +11 −0 examples/time_zone.js
  6. +4 −4 lib/country.js
View
16 README.md
@@ -13,23 +13,33 @@ You can download free geo databases here: http://dev.maxmind.com/geoip/geolite.
npm install maxmind
+
+## Main features
+
+ - Location lookup
+ - Country lookup
+ - Distance between two IP addresses (locations)
+ - Timezone lookup by IP
+
## Usage
+** see code samples in `./examples` directory **
+
City/Location lookup
var maxmind = require('maxmind');
maxmind.init('/path/to/GeoLiteCity.dat')
- console.log(maxmind.getLocation("87.229.134.24"));
+ console.log(maxmind.getLocation("66.6.44.4"));
Country Lookup
var maxmind = require('maxmind');
maxmind.init('/path/to/GeoIP.dat')
- console.log(maxmind.getCountry("87.229.134.24"));
+ console.log(maxmind.getCountry("66.6.44.4"));
## Disclaimer
Module is quite fresh and some sirius bugs are possible. Feel free to
send pull request / bug reports.
-Module currently work only in MEMORY_CACHE mode.
+Module currently work only in `MEMORY_CACHE` mode.
View
16 examples/city.js
@@ -0,0 +1,16 @@
+
+var maxmind = require('maxmind');
+maxmind.init(__dirname + '/GeoLiteCity.dat')
+
+var l = maxmind.getLocation("66.6.44.4");
+
+console.log('countryCode\t', l.countryCode);
+console.log('countryName\t', l.countryName);
+console.log('region\t\t', l.region);
+console.log('city\t\t', l.city);
+console.log('postalCode\t', l.postalCode);
+console.log('latitude\t', l.latitude);
+console.log('longitude\t', l.longitude);
+console.log('metro_code\t', l.metro_code);
+console.log('dma_code\t', l.dma_code);
+console.log('area_code\t', l.area_code);
View
8 examples/country.js
@@ -0,0 +1,8 @@
+
+var maxmind = require('maxmind');
+maxmind.init(__dirname + '/GeoIP.dat')
+
+var c = maxmind.getCountry("66.6.44.4");
+
+console.log('countryCode\t', c.code);
+console.log('countryName\t', c.name);
View
10 examples/distance.js
@@ -0,0 +1,10 @@
+
+var maxmind = require('maxmind');
+maxmind.init(__dirname + '/GeoLiteCity.dat')
+
+var l1 = maxmind.getLocation("66.6.44.4");
+var l2 = maxmind.getLocation("213.180.193.3");
+
+console.log('From:\t', l1.countryName, l1.city);
+console.log('To:\t', l2.countryName, l2.city);
+console.log('Dist:\t', l2.distance(l1));
View
11 examples/time_zone.js
@@ -0,0 +1,11 @@
+
+var maxmind = require('maxmind'),
+ timeZone = require('maxmind/lib/time_zone');
+
+maxmind.init(__dirname + '/GeoLiteCity.dat')
+
+var l = maxmind.getLocation("66.6.44.4");
+
+console.log('countryCode\t', l.countryCode);
+console.log('countryName\t', l.countryName);
+console.log('timeZone\t', timeZone(l.countryCode, l.region));
View
8 lib/country.js
@@ -7,16 +7,16 @@
*/
function Country(code, name) {
- var _code = code,
- _name = name;
+ this.code = code;
+ this.name = name;
/**
* Returns the ISO two-letter country code of this country.
*
* @return the country code.
*/
this.getCode = function() {
- return _code;
+ return this.code;
}
/**
@@ -25,7 +25,7 @@ function Country(code, name) {
* @return the country name.
*/
this.getName = function() {
- return _name;
+ return this.name;
}
}

0 comments on commit f175e4c

Please sign in to comment.
Something went wrong with that request. Please try again.