Never had to do this one and getting confused about the format and how to access specific variables out of it.
The result of :
$result = json_decode($result);
print_r($result);
is :
stdClass Object
(
[input] => stdClass Object
(
[address_components] => stdClass Object
(
[number] => 1109
[predirectional] => N
[street] => Highland
[suffix] => St
[formatted_street] => N Highland St
[city] => Arlington
[state] => VA
[zip] => 22201
[country] => US
)
[formatted_address] => 1109 N Highland St, Arlington, VA 22201
)
[results] => Array
(
[0] => stdClass Object
(
[address_components] => stdClass Object
(
[number] => 1109
[predirectional] => N
[street] => Highland
[suffix] => St
[formatted_street] => N Highland St
[city] => Arlington
[county] => Arlington County
[state] => VA
[zip] => 22201
[country] => US
)
[formatted_address] => 1109 N Highland St, Arlington, VA 22201
[location] => stdClass Object
(
[lat] => 38.886672
[lng] => -77.094735
)
[accuracy] => 1
[accuracy_type] => rooftop
[source] => Arlington
)
[1] => stdClass Object
(
[address_components] => stdClass Object
(
[number] => 1109
[predirectional] => N
[street] => Highland
[suffix] => St
[formatted_street] => N Highland St
[city] => Arlington
[county] => Arlington County
[state] => VA
[zip] => 22201
[country] => US
)
[formatted_address] => 1109 N Highland St, Arlington, VA 22201
[location] => stdClass Object
(
[lat] => 38.886665
[lng] => -77.094733
)
[accuracy] => 1
[accuracy_type] => rooftop
[source] => Virginia Geographic Information Network (VGIN)
)
)
)
How can I access the lat and lng values? I am getting confused since there are objects and arrays mixed within. I've never worked with json in this manner with php... it is a geocoding api that returns in json format.
I basically want to do something like $lat = $result['results'][0]['location']['lat']; and so on.