0

私のコードは

$result = file_get_contents("http://maps.googleapis.com/maps/api/geocode/json?address=".$stateName.",".$districtName.",".$cityName."&sensor=true");

ここで$stateName$districtName$cityNameはユーザーが指定した値です KeralaErnakulamAngamalystateNamedistrictNamecityName
として 入力した後、次のような結果が得られました。

{
    "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"
}

その場所の緯度と経度が必要です。geometry->bounds->northeastから緯度経度を取得するにはどうすればよいですか?

4

1 に答える 1

2
$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;
于 2012-12-18T05:59:06.933 に答える