I've searched and found numerous posts that seem to address this but none seem to work for me. I'm hoping someone with real experience (I'll admit I'm just a hack at this stuff) can point me in the correct direction.
I'm pulling data from an FCC API. Their URL is
https://geo.fcc.gov/api/census/area?lat=47.91631&lon=-120.19647&format=json
Its purpose is to submit a LAT and LON to retrieve State and County info.
It returns JSON as:
{
"input": {
"lat": 47.91631,
"lon": -120.19647
},
"results": [
{
"block_fips": "530079604003023",
"bbox": [
-120.197547,
47.90941,
-120.190388,
47.920194
],
"county_fips": "53007",
"county_name": "Chelan",
"state_fips": "53",
"state_code": "WA",
"state_name": "Washington",
"block_pop_2015": 25,
"amt": "AMT007",
"bea": "BEA169",
"bta": "BTA468",
"cma": "CMA694",
"eag": "EAG006",
"ivm": "IVM694",
"mea": "MEA046",
"mta": "MTA024",
"pea": "PEA206",
"rea": "REA006",
"rpc": "RPC005",
"vpc": "VPC007"
}
]
}
I want to get the "county_name" and "state_code" fields. Here is the code I've plagiarized and am trying to make work.
...
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://geo.fcc.gov/api/census/area?lat=47.91631&lon=-120.19647&format=json",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
"cache-control: no-cache"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
$response = json_decode($response, true); //because of true, it's in an array
echo "County & State: ". $response['county_name']['state_code'];
...