@@ -38,65 +38,61 @@ $ npm install ip-geolocation-api-javascript-sdk
3838``` javascript
3939var IPGeolocationAPI = require (' ip-geolocation-api-javascript-sdk' );
4040
41- // Create IPGeolocationAPI object, passing your valid API key
41+ // Create IPGeolocationAPI object, passing your valid API key (optional) and async requests mode (optional, default: true)
4242var ipgeolocationApi = new IPGeolocationAPI (" YOUR_API_KEY" );
4343
44- // If you want to authorize your requests by your _Request Origin_, you can create IPGeolocationAPI object without an API key.
44+ // Turn off async mode
45+ var ipgeolocationApi = new IPGeolocationAPI (" YOUR_API_KEY" , false );
46+
47+ // If you want to authorize your requests by your "Request Origin", you can create IPGeolocationAPI object without an API key
4548var ipgeolocationApi = new IPGeolocationAPI ();
49+
50+ // Turn off async mode
51+ var ipgeolocationApi = new IPGeolocationAPI (false );
4652```
4753
4854### Geolocation Lookup
4955
5056``` javascript
51- var GeolocationParams = require (' ip-geolocation-api-javascript-sdk/GeolocationParams.js' );
52-
53- // Query geolocation for the calling machine's IP address for all fields
54- ipgeolocationApi .getGeolocation (null , geoResponse);
55- function geoResponse (json ) {
57+ // Function to handle response from IP Geolocation API
58+ function handleResponse (json ) {
5659 console .log (json);
5760}
5861
59- // Query geolocation for IP address (1.1.1.1) and all fields
62+ var GeolocationParams = require (' ip-geolocation-api-javascript-sdk/GeolocationParams.js' );
63+
64+ // Query geolocation for an IP address "1.1.1.1" and all fields
6065var geolocationParams = new GeolocationParams ();
61- geolocationParams .setIp (" 1.1.1.1" );
66+ geolocationParams .setIPAddress (" 1.1.1.1" );
6267
63- ipgeolocationApi .getGeolocation (geolocationParams, geoResponse );
64- function geoResponse ( json ) {
65- console . log (json);
66- }
68+ ipgeolocationApi .getGeolocation (handleResponse, geolocationParams );
69+
70+ // Query geolocation for the calling machine's IP address for all fields
71+ ipgeolocationApi . getGeolocation (handleResponse);
6772
68- // Query geolocation for IP address ( 1.1.1.1) and fields ( geo, time_zone and currency)
73+ // Query geolocation for an IP address " 1.1.1.1" and fields " geo, time_zone, currency"
6974var geolocationParams = new GeolocationParams ();
70- geolocationParams .setIp (" 1.1.1.1" );
75+ geolocationParams .setIPAddress (" 1.1.1.1" );
7176geolocationParams .setFields (" geo,time_zone,currency" );
7277
73- ipgeolocationApi .getGeolocation (geolocationParams, geoResponse);
74- function geoResponse (json ) {
75- console .log (json);
76- }
78+ ipgeolocationApi .getGeolocation (handleResponse, geolocationParams);
7779```
7880
7981### Bulk Geolocations Lookup
8082
8183``` ts
8284// Query geolocations for multiple IP addresses and all fields
8385var geolocationParams = new GeolocationParams ();
84- geolocationParams .setIPList ([ ' 1.1.1.1' , ' 2.2.2.2' , ' 3.3.3.3' ]);
86+ geolocationParams .setIPAddresses ([ " 1.1.1.1" , " 2.2.2.2" , " 3.3.3.3" ]);
8587
86- ipgeolocationApi .getGeolocation (geolocationParams , geoResponse );
87- function geoResponse(json ) {
88- console .log (json );
89- }
88+ ipgeolocationApi .getGeolocation (handleResponse , geolocationParams );
9089
9190// Query geolocations for multiple IP addresses but only 'geo' field
9291var geolocationParams = new GeolocationParams ();
93- geolocationParams .setIPList ([ ' 1.1.1.1' , ' 2.2.2.2' , ' 3.3.3.3' ]);
92+ geolocationParams .setIPAddresses ([ " 1.1.1.1" , " 2.2.2.2" , " 3.3.3.3" ]);
9493geolocationParams .setFields (" geo" );
9594
96- ipgeolocationApi .getGeolocation (geolocationParams , geoResponse );
97- function geoResponse(json ) {
98- console .log (json );
99- }
95+ ipgeolocationApi .getGeolocation (handleResponse , geolocationParams );
10096```
10197
10298### Time Zone API
@@ -108,32 +104,20 @@ var TimezoneParams = require('ip-geolocation-api-javascript-sdk/TimezoneParams.j
108104var timezoneParams = new TimezoneParams ();
109105timezoneParams .setTimezone (" America/New_York" );
110106
111- ipgeolocationApi .getTimezone (timezoneParams , geoResponse );
112- function geoResponse(json ) {
113- console .log (json );
114- }
107+ ipgeolocationApi .getTimezone (handleResponse , timezoneParams );
115108
116109// Query time zone information by latitude and longitude of the location
117110var timezoneParams = new TimezoneParams ();
118- timezoneParams .setLocation (37.1838139 , - 123.8105225 );
111+ timezoneParams .setCoordinates (37.1838139 , - 123.8105225 );
119112
120- ipgeolocationApi .getTimezone (timezoneParams , geoResponse );
121- function geoResponse(json ) {
122- console .log (json );
123- }
113+ ipgeolocationApi .getTimezone (handleResponse , timezoneParams );
124114
125- // Query time zone information for IP address ( 1.1.1.1)
115+ // Query time zone information for IP address " 1.1.1.1"
126116var timezoneParams = new TimezoneParams ();
127- timezoneParams .setIp (" 1.1.1.1" );
117+ timezoneParams .setIPAddress (" 1.1.1.1" );
128118
129- ipgeolocationApi .getTimezone (timezoneParams , timeZoneResponse );
130- function timeZoneResponse(json ) {
131- console .log (json );
132- }
119+ ipgeolocationApi .getTimezone (handleResponse , timezoneParams );
133120
134121// Query time zone information for calling machine’s IP address
135- ipgeolocationApi .getTimezone (null , timeZoneResponse );
136- function timeZoneResponse(json ) {
137- console .log (json );
138- }
122+ ipgeolocationApi .getTimezone (handleResponse );
139123```
0 commit comments