@@ -36,19 +36,12 @@ $ npm install ip-geolocation-api-javascript-sdk
3636### Setup API
3737
3838``` javascript
39- var IPGeolocationAPI = require (' ip-geolocation-api-javascript-sdk/IPGeolocationAPI ' );
39+ var IPGeolocationAPI = require (' ip-geolocation-api-javascript-sdk' );
4040
41- // Create IPGeolocationAPI object, passing your valid API key (optional) and async requests mode (optional, default: true)
42- var ipgeolocationApi = new IPGeolocationAPI (" YOUR_API_KEY" );
43-
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
48- var ipgeolocationApi = new IPGeolocationAPI ();
49-
50- // Turn off async mode
51- var ipgeolocationApi = new IPGeolocationAPI (false );
41+ // Create IPGeolocationAPI object. Constructor takes two parameters.
42+ // 1) API key (Optional: To authenticate your requests through "Request Origin", you can skip it.)
43+ // 2) Async (Optional: It is used to toggle "async" mode in the requests. By default, it is true.)
44+ var ipgeolocationApi = new IPGeolocationAPI (" YOUR_API_KEY" , false );
5245```
5346
5447### Geolocation Lookup
@@ -61,63 +54,86 @@ function handleResponse(json) {
6154
6255var GeolocationParams = require (' ip-geolocation-api-javascript-sdk/GeolocationParams.js' );
6356
64- // Query geolocation for an IP address "1.1.1.1" and all fields
57+ // Get complete geolocation for the calling machine's IP address
58+ ipgeolocationApi .getGeolocation (handleResponse);
59+
60+ // Get complete geolocation in Russian** for IP address (1.1.1.1)
6561var geolocationParams = new GeolocationParams ();
66- geolocationParams .setIPAddress (" 1.1.1.1" );
62+ geolocationParams .setIPAddress (' 1.1.1.1' );
63+ geolocationParams .setLang (' ru' );
6764
6865ipgeolocationApi .getGeolocation (handleResponse, geolocationParams);
6966
70- // Query geolocation for the calling machine's IP address for all fields
71- ipgeolocationApi .getGeolocation (handleResponse);
67+ // Get custom geolocation (only "geo, time_zone and currency" fields/objects) for an IP address (1.1.1.1)
68+ var geolocationParams = new GeolocationParams ();
69+ geolocationParams .setIPAddress (' 1.1.1.1' );
70+ geolocationParams .setFields (' geo,time_zone,currency' );
7271
73- // Query geolocation for an IP address "1.1.1.1" and fields "geo, time_zone, currency"
72+ ipgeolocationApi .getGeolocation (handleResponse, geolocationParams);
73+
74+ // Exclude fields/obejects from complete geolocation in Italian language
7475var geolocationParams = new GeolocationParams ();
75- geolocationParams .setIPAddress ( " 1.1.1.1 " );
76- geolocationParams .setFields ( " geo,time_zone,currency " );
76+ geolocationParams .setExcludes ( ' continent_name,country_code3,time_zone ' );
77+ geolocationParams .setLang ( ' it ' );
7778
7879ipgeolocationApi .getGeolocation (handleResponse, geolocationParams);
7980```
8081
8182### Bulk Geolocations Lookup
8283
8384``` ts
84- // Query geolocations for multiple IP addresses and all fields
85+ // Query geolocation in German** for multiple IP addresses and all fields
8586var geolocationParams = new GeolocationParams ();
86- geolocationParams .setIPAddresses ([" 1.1.1.1" , " 2.2.2.2" , " 3.3.3.3" ]);
87+ geolocationParams .setLang (' de' );
88+ geolocationParams .setIPAddresses ([' 1.1.1.1' , ' 2.2.2.2' , ' 3.3.3.3' ]);
8789
8890ipgeolocationApi .getGeolocation (handleResponse , geolocationParams );
8991
90- // Query geolocations for multiple IP addresses but only 'geo' field
92+ // Specify the required fields/objects for multiple IP addresses
9193var geolocationParams = new GeolocationParams ();
92- geolocationParams .setIPAddresses ([" 1.1.1.1" , " 2.2.2.2" , " 3.3.3.3" ]);
93- geolocationParams .setFields (" geo" );
94+ geolocationParams .setIPAddresses ([' 1.1.1.1' , ' 2.2.2.2' , ' 3.3.3.3' ]);
95+ geolocationParams .setFields (' geo' );
9496
95- ipgeolocationApi .getGeolocation (handleResponse , geolocationParams );
97+ ipgeolocationApi .getGeolocation (geolocationParams , geoResponse );
9698```
9799
98- ### Time Zone API
100+ ### Timezone API
99101
100102``` ts
101103var TimezoneParams = require (' ip-geolocation-api-javascript-sdk/TimezoneParams.js' );
102104
103- // Query time zone information by time zone ID
105+ // Get time zone information by time zone ID
104106var timezoneParams = new TimezoneParams ();
105- timezoneParams .setTimezone (" America/New_York " );
107+ timezoneParams .setTimezone (' America/Los_Angeles ' );
106108
107109ipgeolocationApi .getTimezone (handleResponse , timezoneParams );
108110
109- // Query time zone information by latitude and longitude of the location
111+ // Get time zone information by latitude and longitude of the location
110112var timezoneParams = new TimezoneParams ();
111- timezoneParams .setCoordinates (37.1838139 , - 123.8105225 );
113+ timezoneParams .setCoordinates (' 37.1838139' , ' -123.8105225' );
112114
113115ipgeolocationApi .getTimezone (handleResponse , timezoneParams );
114116
115- // Query time zone information for IP address " 1.1.1.1"
117+ // Get time zone information for IP address ( 1.1.1.1) and geolocation information Japanese**
116118var timezoneParams = new TimezoneParams ();
117- timezoneParams .setIPAddress (" 1.1.1.1" );
119+ timezoneParams .setIPAddress (' 1.1.1.1' );
118120
119121ipgeolocationApi .getTimezone (handleResponse , timezoneParams );
120122
121- // Query time zone information for calling machine’ s IP address
123+ // Query time zone information for calling machine' s IP address
122124ipgeolocationApi .getTimezone (handleResponse );
123125```
126+
127+ ** IPGeolocation provides geolocation information in the following languages:
128+
129+ * English (en)
130+ * German (de)
131+ * Russian (ru)
132+ * Japanese (ja)
133+ * French (fr)
134+ * Chinese Simplified (cn)
135+ * Spanish (es)
136+ * Czech (cs)
137+ * Italian (it)
138+
139+ By default, geolocation information is returned in English. Response in a language other than English is available to paid users only.
0 commit comments