私はどこでも答えを探していますが、見つからなかった。私はLat、LongからAddressを表示するためにgoogle map geolocation APIを使用しています。私は配列の"formatted_address"のような選択的なデータだけを表示する必要があります。これは私がPHPで応答を表示しようとしているコードです:GOOGLE MAPS GEOLOCATION APIのPHPからの応答を取得すると、出力はJSONになります
$file_contents = file_get_contents("http://maps.googleapis.com/maps/api/geocode/json?latlng=31.334097,74.235875&sensor=false", true);
$data = json_decode($file_contents, true);
foreach($data as $output => $var) {
echo $var;
}
はこれが応答である:[https://maps.googleapis.com/maps/api/geocode/json?latlng=31.334097,74.235875]
これは私が手出力されます:
Notice: Array to string conversion in C:\xampp\htdocs\bikewala\myaccount\index.php on line 176
ArrayOK
私がしようとすると、
$file_contents = file_get_contents("http://maps.googleapis.com/maps/api/geocode/json?latlng=31.334097,74.235875&sensor=false", true);
$data = json_decode($file_contents, true);
foreach($data as $output => $var) {
echo $var['formatted_address'];
}
私はこのエラーを受け取ります:
Notice: Undefined index: formatted_address in C:\xampp\htdocs\bikewala\myaccount\index.php on line 176
Warning: Illegal string offset 'formatted_address' in C:\xampp\htdocs\bikewala\myaccount\index.php on line 176
O
私はここで間違っていますか?
ありがとうございます!
素晴らしい!トリックをしました。本当にありがとう! –
全く問題ありません:) – Solor