Skip to content

Instantly share code, notes, and snippets.

@MattSandy
Created September 21, 2015 20:58
Show Gist options
  • Save MattSandy/d1b4a27874d364f07863 to your computer and use it in GitHub Desktop.
Save MattSandy/d1b4a27874d364f07863 to your computer and use it in GitHub Desktop.
Checks if within a defined box based on longitude and latitude
<?php
$url = 'https://api.smartystreets.com/street-address?';
$url .= 'auth-id=[auth-id]&auth-token=[auth-token]';
$url .= '&street=' . $street . '&zipcode=' . $zip;
$urlData = json_decode(file_get_contents($url),true);
//print_r($urlData);
if(isset($urlData[0]['metadata']['latitude'])) {
$latitude = $urlData[0]['metadata']['latitude'];
$longitude = $urlData[0]['metadata']['longitude'];
//latitude check
if(($latitude<$latitudeTopLeft)&&($latitude>$latitudeBottomLeft)) {
//longitude check
if(($longitude>$longitudeTopLeft)&&($longitude<$longitudeTopRight)) {
$zone = true;
}
}
}
else {
$zone = false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment