Skip to content

Commit c0b89ff

Browse files
committed
Examples updated
1 parent 1c3e959 commit c0b89ff

File tree

2 files changed

+32
-17
lines changed

2 files changed

+32
-17
lines changed

README.md

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ IPGeolocationAPI api = new IPGeolocationAPI("YOUR_API_KEY");
8484
### Geolocation Lookup
8585

8686
```java
87-
// Query geolocation for IP address (1.1.1.1) and fields (geo, time_zone and currency)
87+
// Get geolocation for IP address (1.1.1.1) and fields (geo, time_zone and currency)
8888
GeolocationParams geoParams = new GeolocationParams();
8989
geoParams.setIPAddress("1.1.1.1");
9090
geoParams.setFields("geo,time_zone,currency");
@@ -100,37 +100,40 @@ if(geolocation.getStatus() == 200) {
100100
System.out.printf("Status Code: %d, Message: %s\n", geolocation.getStatus(), geolocation.getMessage());
101101
}
102102

103-
// Query geolocation for IP address (1.1.1.1) and all fields
103+
// Get geolocation in Russian** for IP address (1.1.1.1) and all fields
104104
GeolocationParams geoParams = new GeolocationParams();
105105
geoParams.setIPAddress("1.1.1.1");
106+
geoParams.setLang("ru");
106107

107108
Geolocation geolocation = api.getGeolocation(geoParams);
108109

110+
// Check if geolocation lookup was successful
109111
if(geolocation.getStatus() == 200) {
110112
System.out.println(geolocation.getIPAddress());
111113
System.out.println(geolocation.getCountryName());
112114
} else {
113-
System.out.printf("Status Code: %d, Message: %s\n", geolocation.getStatus(), geolocation.getMessage());
115+
System.out.printf("Status Code: %d, Message: %s\n", geolocation.getStatus(), geolocation.getMessage());
114116
}
115117

116-
// Query geolocation for the calling machine's IP address for all fields
118+
// Get geolocation for the calling machine's IP address for all fields
117119
Geolocation geolocation = api.getGeolocation();
118120

119121
if(geolocation.getStatus() == 200) {
120122
System.out.println(geolocation.getCountryCode2());
121123
System.out.println(geolocation.getTimezone().getCurrentTime());
122124
} else {
123-
System.out.printf("Status Code: %d, Message: %s\n", geolocation.getStatus(), geolocation.getMessage());
125+
System.out.printf("Status Code: %d, Message: %s\n", geolocation.getStatus(), geolocation.getMessage());
124126
}
125127
```
126128

127129
### Bulk Geolocations Lookup
128130

129131
```java
130-
// Query geolocations for multiple IP addresses and all fields
131-
String[] ips = new String[] {"1.1.1.1", "2.2.2.2", "3.3.3.3"};
132+
// Query geolocation in German** for multiple IP addresses and all fields
133+
String[] ips = new String[]{"1.1.1.1", "2.2.2.2", "3.3.3.3"};
132134
GeolocationParams geoParams = new GeolocationParams();
133135
geoParams.setIPAddresses(ips);
136+
geoParams.setLang("de");
134137

135138
List<Geolocation> geolocations = api.getBulkGeolocation(geoParams);
136139

@@ -140,7 +143,7 @@ System.out.println(geolocations.get(1).getLanguages());
140143
System.out.println(geolocations.get(2).getTimezone().getCurrentTime());
141144

142145
// Query geolocations for multiple IP addresses but only geo field
143-
String[] ips = new String[] {"1.1.1.1", "2.2.2.2", "3.3.3.3"};
146+
String[] ips = new String[]{"1.1.1.1", "2.2.2.2", "3.3.3.3"};
144147
GeolocationParams geoParams = new GeolocationParams();
145148
geoParams.setIPAddresses(ips);
146149
geoParams.setFields("geo");
@@ -153,10 +156,10 @@ System.out.println(geolocations.get(1).getCountryName());
153156
System.out.println(geolocations.get(2).getLatitude());
154157
```
155158

156-
### Time Zone API
159+
### Timezone API
157160

158161
```java
159-
// Query time zone information by time zone ID
162+
// Get time zone information by time zone ID
160163
TimezoneParams tzParams = new TimezoneParams();
161164
tzParams.setTimezone("America/New_York");
162165

@@ -166,10 +169,10 @@ if(tz.getStatus() == 200) {
166169
System.out.println(tz.getDateTimeWti());
167170
System.out.println(tz.getDateTimeTxt());
168171
} else {
169-
System.out.printf("Status Code: %d, Message: %s\n", geolocation.getStatus(), geolocation.getMessage());
172+
System.out.printf("Status Code: %d, Message: %s\n", geolocation.getStatus(), geolocation.getMessage());
170173
}
171174

172-
// Query time zone information by latitude and longitude of the location
175+
// Get time zone information by latitude and longitude of the location
173176
TimezoneParams tzParams = new TimezoneParams();
174177
tzParams.setLocation(37.1838139, -123.8105225);
175178

@@ -178,17 +181,18 @@ Timezone tz = api.getTimezone(tzParams);
178181
if(tz.getStatus() == 200) {
179182
System.out.println(tz.getTimezone());
180183
} else {
181-
System.out.println(tz.getMessage());
184+
System.out.printf("Status Code: %d, Message: %s\n", geolocation.getStatus(), geolocation.getMessage());
182185
}
183186

184-
// Query time zone information for IP address (1.1.1.1)
187+
// Get time zone information for IP address (1.1.1.1) and geolocation information Japanese**
185188
TimezoneParams tzParams = new TimezoneParams();
186189
tzParams.setIPAddress("1.1.1.1");
190+
tzParams.setLang("ja");
187191

188192
Timezone tz = api.getTimezone(tzParams);
189193

190194
if(tz.getStatus() == 200) {
191-
System.out.println(tz.toString());
195+
System.out.println(tz.getTimezone());
192196
} else {
193197
System.out.printf("Status Code: %d, Message: %s\n", geolocation.getStatus(), geolocation.getMessage());
194198
}
@@ -204,6 +208,19 @@ if(tz.getMessage()) {
204208
}
205209
```
206210

211+
** IPGeolocation provides geolocation information in the following languages:
212+
* English (en)
213+
* German (de)
214+
* Russian (ru)
215+
* Japanese (ja)
216+
* French (fr)
217+
* Chinese Simplified (cn)
218+
* Spanish (es)
219+
* Czech (cs)
220+
* Italian (it)
221+
222+
By default, geolocation information is returned in English. Response in a language other than English is available to paid users only.
223+
207224
## IP Geolocation API Java SDK Objects Reference
208225

209226
IP Geolocation API Java SDK has following classes that you can use to fully leverage it.

pom.xml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,4 @@
4545
<properties>
4646
<java.version>1.8</java.version>
4747
</properties>
48-
49-
5048
</project>

0 commit comments

Comments
 (0)