-
Notifications
You must be signed in to change notification settings - Fork 20
/
USReverseGeoExample.cs
88 lines (75 loc) · 2.81 KB
/
USReverseGeoExample.cs
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
namespace Examples
{
using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using SmartyStreets;
using SmartyStreets.USReverseGeoApi;
internal static class USReverseGeoExample
{
public static void Run()
{
// specifies the TLS protocoll to use - this is TLS 1.2
const SecurityProtocolType tlsProtocol1_2 = (SecurityProtocolType)3072;
// var authId = "Your SmartyStreets Auth ID here";
// var authToken = "Your SmartyStreets Auth Token here";
// We recommend storing your keys in environment variables instead---it's safer!
var authId = Environment.GetEnvironmentVariable("SMARTY_AUTH_ID");
var authToken = Environment.GetEnvironmentVariable("SMARTY_AUTH_TOKEN");
ServicePointManager.SecurityProtocol = tlsProtocol1_2;
// The appropriate license values to be used for your subscriptions
// can be found on the Subscriptions page the account dashboard.
// https://www.smartystreets.com/docs/cloud/licensing
var client = new ClientBuilder(authId, authToken).WithLicense(new List<string>{"us-reverse-geocoding-cloud"})
//.WithCustomBaseUrl("us-street-reverse-geo.api.smarty.com")
//.ViaProxy("http://localhost:8080", "username", "password") // uncomment this line to point to the specified proxy.
.BuildUsReverseGeoApiClient();
// Documentation for input fields can be found at:
// https://smartystreets.com/docs/us-street-api#input-fields
var lookup = new Lookup(40.111111, -111.111111);
//uncomment the line below to add a custom parameter
//lookup.AddCustomParameter("source", "all");
try
{
client.Send(lookup);
}
catch (SmartyException ex)
{
Console.WriteLine(ex.Message);
Console.WriteLine(ex.StackTrace);
return;
}
catch (IOException ex)
{
Console.WriteLine(ex.StackTrace);
return;
}
if (lookup.SmartyResponse == null)
{
Console.WriteLine("No candidates.");
return;
}
var results = lookup.SmartyResponse.Results;
if (results.Count == 0)
{
Console.WriteLine("No candidates. This means the address is not valid.");
return;
}
Console.WriteLine("\nResults for input: (" + lookup.Latitude + ", " + lookup.Longitude);
foreach (var result in results)
{
var coordinate = result.Coordinate;
var address = result.Address;
Console.WriteLine("\nLatitude: " + coordinate.Latitude);
Console.WriteLine("Longitude: " + coordinate.Longitude);
Console.WriteLine("Distance: " + result.Distance);
Console.WriteLine("Street: " + address.Street);
Console.WriteLine("City: " + address.City);
Console.WriteLine("State Abbreviation: " + address.StateAbbreviation);
Console.WriteLine("ZIP Code: " + address.ZipCode);
Console.WriteLine("License: " + coordinate.License);
}
}
}
}