Quick Start Guide

In this document, you will go through the basic steps to use IP Geolocation API Javascript SDK.
You need a valid 'IPGeolocation API key' to use this SDK. Sign up here and get your free API key if you don't have one.

System Requirements

Internet connection is required to run this component.

Installation

NPM

$ npm install ip-geolocation-api-javascript-sdk

Basic Usage

Setup API

var IPGeolocationAPI = require('ip-geolocation-api-javascript-sdk');

// Create IPGeolocationAPI object, passing your valid API key
var ipgeolocationApi = new IPGeolocationAPI("YOUR_API_KEY");

Geolocation Lookup

var GeolocationParams = require('ip-geolocation-api-javascript-sdk/GeolocationParams.js');

// Query geolocation for the calling machine's IP address for all fields
console.log(ipgeolocationApi.getGeolocation());

// Query geolocation for IP address (1.1.1.1) and all fields
var geolocationParams = new GeolocationParams();
geolocationParams.setIp("1.1.1.1");

console.log(ipgeolocationApi.getGeolocation(geolocationParams));

// Query geolocation for IP address (1.1.1.1) and fields (geo, time_zone and currency)
var geolocationParams = new GeolocationParams();
geolocationParams.setIp("1.1.1.1"); 
geolocationParams.setFields("geo,time_zone,currency");

console.log(ipgeolocationApi.getGeolocation(geolocationParams));

Bulk Geolocations Lookup

// Query geolocations for multiple IP addresses and all fields
var geolocationParams = new GeolocationParams();
geolocationParams.setIps(['1.1.1.1', '2.2.2.2', '3.3.3.3']);

console.log(ipgeolocationApi.getGeolocation(geolocationParams));

// Query geolocations for multiple IP addresses but only 'geo' field
var geolocationParams = new GeolocationParams();
geolocationParams.setIps(['1.1.1.1', '2.2.2.2', '3.3.3.3']);
geolocationParams.setFields("geo");

console.log(ipgeolocationApi.getGeolocation(geolocationParams));

Time Zone API

var TimezoneParams = require('ip-geolocation-api-javascript-sdk/TimezoneParams.js');

// Query time zone information by time zone ID
var timezoneParams = new TimezoneParams();
timezoneParams.setTimezone("America/New_York");

console.log(ipgeolocationApi.getTimezone(timezoneParams));

// Query time zone information by latitude and longitude of the location
var timezoneParams = new TimezoneParams();
timezoneParams.setLocation(37.1838139, -123.8105225);

console.log(ipgeolocationApi.getTimezone(timezoneParams));

// Query time zone information for IP address (1.1.1.1)
var timezoneParams = new TimezoneParams();
timezoneParams.setIp("1.1.1.1");

console.log(ipgeolocationApi.getTimezone(timezoneParams));

// Query time zone information for calling machine?s IP address
console.log(ipgeolocationApi.getTimezone());