Quick Start Guide

In this document, you will go through the basic steps to use IP Geolocation API Typescript 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-sdk-typescript

Basic Usage

Setup API

import {IPGeolocationAPI} from './node_modules/ip-geolocation-api-sdk-typescript/IPGeolocationAPI';

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

Geolocation Lookup

import {GeolocationParams} from './node_modules/ip-geolocation-api-sdk-typescript/GeolocationParams';

// 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
let 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)
let 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
let 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
let 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

import {GeolocationParams} from './node_modules/ip-geolocation-api-sdk-typescript/TimezoneParams';

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

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

// Query time zone information by latitude and longitude of the location
let 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)
let 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());

Commands To Run Typescript Application

  1. tsc *.ts
  2. node *.js