0

私のプログラマーはlocation、このjson配列からデータ(緯度と経度)を取得するのに問題があります。foreachの緯度/経度を見つけてlocation:それらをエコーするループは何でしょうか?ありがとう

$jsonArray = json_decode($jsondata, true);

$jsondata =  {
       "results" : [
          {
             "address_components" : [
                {
                   "long_name" : "2340",
                   "short_name" : "2340",
                   "types" : [ "postal_code" ]
                },
                {
                   "long_name" : "New South Wales",
                   "short_name" : "NSW",
                   "types" : [ "administrative_area_level_1", "political" ]
                },
                {
                   "long_name" : "Australia",
                   "short_name" : "AU",
                   "types" : [ "country", "political" ]
                }
             ],
             "formatted_address" : "New South Wales 2340, Australia",
             "geometry" : {
                "bounds" : {
                   "northeast" : {
                      "lat" : -30.79897870,
                      "lng" : 151.394080
                   },
                   "southwest" : {
                      "lat" : -31.661670,
                      "lng" : 150.334880
                   }
                },
                "location" : {
                   "lat" : -31.28146910,
                   "lng" : 151.04713550
                },
                "location_type" : "APPROXIMATE",
                "viewport" : {
                   "northeast" : {
                      "lat" : -30.79897870,
                      "lng" : 151.394080
                   },
                   "southwest" : {
                      "lat" : -31.661670,
                      "lng" : 150.334880
                   }
                }
             },
             "types" : [ "postal_code" ]
          }
       ],
       "status" : "OK"
    };
4

1 に答える 1

3

なぜループが必要なのですか?次のコマンドで直接アクセスできます。

echo $jsonArray['results'][0]['geometry']['location']['lat'];

複数の結果がある場合は、

foreach( $jsonArray['results'] as $row) { 
    $lat = $row['geometry']['location']['lat'];
    $long = $row['geometry']['location']['lng'];
    echo $lat . ' ' . $long . "\n";
}
于 2012-08-01T19:24:27.657 に答える