-
Notifications
You must be signed in to change notification settings - Fork 18
/
UsReverseGeoExample.java
58 lines (47 loc) · 2.65 KB
/
UsReverseGeoExample.java
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
48
49
50
51
52
53
54
55
56
57
58
package examples;
import com.smartystreets.api.ClientBuilder;
import com.smartystreets.api.SharedCredentials;
import com.smartystreets.api.StaticCredentials;
import com.smartystreets.api.exceptions.SmartyException;
import com.smartystreets.api.us_reverse_geo.*;
import java.io.IOException;
import java.util.ArrayList;
public class UsReverseGeoExample {
public static void main(String[] args) {
// We recommend storing your authentication credentials in environment variables.
// for server-to-server requests, use this code:
//StaticCredentials credentials = new StaticCredentials(System.getenv("SMARTY_AUTH_ID"), System.getenv("SMARTY_AUTH_TOKEN"));
// for client-side requests (browser/mobile), use this code:
SharedCredentials credentials = new SharedCredentials(System.getenv("SMARTY_AUTH_WEB"), System.getenv("SMARTY_AUTH_REFERER"));
// The appropriate license values to be used for your subscriptions
// can be found on the Subscriptions page of the account dashboard.
// https://www.smartystreets.com/docs/cloud/licensing
ArrayList<String> licenses = new ArrayList<>();
licenses.add("us-reverse-geocoding-cloud");
Client client = new ClientBuilder(credentials).withLicenses(licenses)
// .withProxy(Proxy.Type.HTTP, "localhost", 8080) // Uncomment this line to try it with a proxy
.buildUsReverseGeoClient();
Lookup lookup = new Lookup(40.27644, -111.65747);
try {
client.send(lookup);
} catch (SmartyException | IOException | InterruptedException ex) {
System.out.println(ex.getMessage());
ex.printStackTrace();
}
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();
}
}
}