forked from smartystreets/smartystreets-php-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUSReverseGeoExample.php
More file actions
69 lines (54 loc) · 2.4 KB
/
USReverseGeoExample.php
File metadata and controls
69 lines (54 loc) · 2.4 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
require_once(__DIR__ . '/../src/StaticCredentials.php');
require_once(__DIR__ . '/../src/ClientBuilder.php');
require_once(__DIR__ . '/../src/US_Reverse_Geo/Lookup.php');
require_once(__DIR__ . '/../src/US_Reverse_Geo/Client.php');
use SmartyStreets\PhpSdk\StaticCredentials;
use SmartyStreets\PhpSdk\ClientBuilder;
use SmartyStreets\PhpSdk\US_Reverse_Geo\Lookup;
$lookupExample = new USReverseGeoExample();
$lookupExample->run();
class USReverseGeoExample
{
public function run()
{
// $authId = 'Your SmartyStreets Auth ID here';
// $authToken = 'Your SmartyStreets Auth Token here';
// We recommend storing your secret keys in environment variables instead---it's safer!
$authId = getenv('SMARTY_AUTH_ID');
$authToken = getenv('SMARTY_AUTH_TOKEN');
$staticCredentials = new StaticCredentials($authId, $authToken);
// 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
$client = (new ClientBuilder($staticCredentials))
->buildUsReverseGeoApiClient();
$lookup = new Lookup(40.111111, -111.111111);
// Uncomment the below line to add a custom parameter to the API call
// $lookup->addCustomParameter("parameter", "value");
try {
$client->sendLookup($lookup);
$this->displayResults($lookup);
}
catch (Exception $ex) {
echo($ex->getMessage());
}
}
public function displayResults(Lookup $lookup)
{
echo("Results for input: " . $lookup->getLatitude() . ", " . $lookup->getLongitude() . "\n");
foreach ($lookup->getResponse()->getResults() as $result) {
$coordinate = $result->getCoordinate();
echo("\nLatitude: " . $coordinate->getLatitude());
echo("\nLongitude: " . $coordinate->getLongitude());
echo("\nDistance: " . $result->getDistance());
$address = $result->getAddress();
echo("\nStreet: " . $address->getStreet());
echo("\nCity: " . $address->getCity());
echo("\nState Abbreviation: " . $address->getStateAbbreviation());
echo("\nZIP Code: " . $address->getZIPCode());
echo("\nLicense: " . $coordinate->getLicense());
echo("\n");
}
}
}