2011-10-28 28 views
0

我試圖在PHP中使用反向地理編碼Web服務.Response JSON僅返回空響應。在Google中返回的空字符串反向地理編碼webservice JSON

$json_string2='http://maps.googleapis.com/maps/api/geocode/json?latlng=11.49813514,77.24331624&sensor=false'; 
$obj2=json_decode($json_string2); 
$addr2=$obj2->formatted_address; 
echo $addr2; //**line 1** 

這裏線1個打印空....什麼是編碼的問題....

回答

1

你的問題是你要解碼JSON之前沒有拿到文件,你也被稱爲格式錯誤。

$json_string2 = file_get_contents('http://maps.googleapis.com/maps/api/geocode/json?latlng=11.49813514,77.24331624&sensor=false'); 
$obj2 = json_decode($json_string2); 
$addr2 = $obj2->results[0]->formatted_address; 
echo $addr2; //**line 1** 

您可以在調用其格式之前嘗試打印此對象。

print_r($obj2);