Skip to content

Instantly share code, notes, and snippets.

@bentigano
Created December 17, 2013 19:00
Show Gist options
  • Save bentigano/8010651 to your computer and use it in GitHub Desktop.
Save bentigano/8010651 to your computer and use it in GitHub Desktop.
Retrieves HUD housing counseling agencies using their API.
<?php
function getClosestHousingCouncelingAgencies($latitude, $longitude, $limit = 10, &$debugData) {
$apiURL = 'http://data.hud.gov/Housing_Counselor/searchByLocation';
$distance = 25;
$agencies = array();
$apiURL = $apiURL . '?Lat=' . $latitude . '&Long=' . $longitude . '&Distance=' . $distance . '&RowLimit=&Services=&Languages=';
$debugData .= 'API: ' . $apiURL . ' <br/>';
$file = file_get_contents($apiURL);
if ($file != false) {
$jsonObject = json_decode($file);
if (is_array($jsonObject)) {
foreach ($jsonObject as $item) {
$agencies[] = $item;
$debugData .= 'Adding item: ' . $item->agcid . ' <br/>';
}
}
}
return $agencies;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment