-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathUsReverseGeoExample.java
More file actions
47 lines (39 loc) · 2.29 KB
/
UsReverseGeoExample.java
File metadata and controls
47 lines (39 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package examples;
import com.smartystreets.api.BasicAuthCredentials;
import com.smartystreets.api.ClientBuilder;
import com.smartystreets.api.exceptions.SmartyException;
import com.smartystreets.api.us_reverse_geo.*;
import java.io.IOException;
public class UsReverseGeoExample {
public static void main(String[] args) {
// We recommend storing your authentication credentials in environment variables.
// for client-side requests (browser/mobile), use this code:
// SharedCredentials credentials = new SharedCredentials(System.getenv("SMARTY_AUTH_WEB"), System.getenv("SMARTY_AUTH_REFERER"));
BasicAuthCredentials credentials = new BasicAuthCredentials(System.getenv("SMARTY_AUTH_ID"), System.getenv("SMARTY_AUTH_TOKEN"));
try (Client client = new ClientBuilder(credentials)
// .withProxy(Proxy.Type.HTTP, "localhost", 8080) // Uncomment this line to try it with a proxy
.buildUsReverseGeoClient()) {
Lookup lookup = new Lookup(40.27644, -111.65747);
client.send(lookup);
Result[] results = lookup.getResponse().getResults();
System.out.printf("Results for input: (%f, %f)\n\n", lookup.getLatitude(), lookup.getLongitude());
for (Result result : results) {
Coordinate coordinate = result.getCoordinate();
Address address = result.getAddress();
System.out.println("Latitude: " + coordinate.getLatitude());
System.out.println("Longitude: " + coordinate.getLongitude());
System.out.println("Distance: " + result.getDistance().toString());
System.out.println("Street: " + address.getStreet());
System.out.println("City: " + address.getCity());
System.out.println("State Abbreviation: " + address.getStateAbbreviation());
System.out.println("ZIP Code: " + address.getZipCode());
System.out.println("License: " + coordinate.getLicense());
System.out.println("Smartykey: " + address.getSmartykey());
System.out.println();
}
} catch (SmartyException | IOException | InterruptedException ex) {
System.out.println(ex.getMessage());
ex.printStackTrace();
}
}
}