I have the following JSON array:
<?php
$json = {
"status": "OK",
"results": [ {
"types": [ "street_address" ],
"formatted_address": "5721 N Northcott Ave, Chicago, IL 60631, USA",
"address_components": [ {
"long_name": "5721",
"short_name": "5721",
"types": [ "street_number" ]
}, {
"long_name": "Illinois",
"short_name": "IL",
"types": [ "administrative_area_level_1", "political" ]
}, {
"long_name": "60631",
"short_name": "60631",
"types": [ "postal_code" ]
} ],
"geometry": {
"location": {
"lat": 41.9858860,
"lng": -87.7907460
},
"location_type": "ROOFTOP",
"viewport": {
"southwest": {
"lat": 41.9827384,
"lng": -87.7938936
},
"northeast": {
"lat": 41.9890336,
"lng": -87.7875984
}
}
}
} ]
};
?>
Using PHP, how do I get the geometery->location->lat
&lng
values from my JSON array above?
For example (pseudo code):
<?php
$lat = $json['geometry']['location']['lat']; // 41.9858860
$lng = $json['geometry']['location']['lng']; // -87.7907460
?>