如何从PHP中使用file_get_contents()函数获取的内容中检索特定数据?

如何从PHP中使用file_get_contents()函数获取的内容中检索特定数据?,php,json,google-maps,Php,Json,Google Maps,我的代码是 $result = file_get_contents("http://maps.googleapis.com/maps/api/geocode/json?address=".$stateName.",".$districtName.",".$cityName."&sensor=true"); 其中,$stateName,$districtName,$cityName是用户给定的值 在进入喀拉拉邦、Ernakulam、Angamaly作为州名、地区名和城市名后,我得到了如下

我的代码是

$result = file_get_contents("http://maps.googleapis.com/maps/api/geocode/json?address=".$stateName.",".$districtName.",".$cityName."&sensor=true");
其中,
$stateName
$districtName
$cityName
是用户给定的值
在进入喀拉拉邦、Ernakulam、Angamaly作为州名、地区名和城市名后,我得到了如下结果:

{
    "results": [
        {
            "address_components": [
                {
                    "long_name": "Angamaly",
                    "short_name": "Angamaly",
                    "types": [
                        "locality",
                        "political"
                    ]
                },
                {
                    "long_name": "Ernakulam",
                    "short_name": "Ernakulam",
                    "types": [
                        "administrative_area_level_2",
                        "political"
                    ]
                },
                {
                    "long_name": "Kerala State",
                    "short_name": "Kerala State",
                    "types": [
                        "administrative_area_level_1",
                        "political"
                    ]
                },
                {
                    "long_name": "India",
                    "short_name": "IN",
                    "types": [
                        "country",
                        "political"
                    ]
                }
            ],
            "formatted_address": "Angamaly, Kerala State, India",
            "geometry": {
                "bounds": {
                    "northeast": {
                        "lat": 10.2464704,
                        "lng": 76.39544959999999
                    },
                    "southwest": {
                        "lat": 10.1585335,
                        "lng": 76.3500451
                    }
                },
                "location": {
                    "lat": 10.212894,
                    "lng": 76.380601
                },
                "location_type": "APPROXIMATE",
                "viewport": {
                    "northeast": {
                        "lat": 10.2464704,
                        "lng": 76.39544959999999
                    },
                    "southwest": {
                        "lat": 10.1585335,
                        "lng": 76.3500451
                    }
                }
            },
            "types": [
                "locality",
                "political"
            ]
        }
    ],
    "status": "OK"
}
我需要这个地方的经纬度。如何从

几何->边界->东北

请看我的答案,测试和工作。
$json = file_get_contents("http://maps.googleapis.com/maps/api/geocode/json?address=".$stateName.",".$districtName.",".$cityName."&sensor=true");

$response = json_decode($json);
echo $response->results[0]->geometry->bounds->northeast->lat;
echo $response->results[0]->geometry->bounds->northeast->lng;