我直接使用地址欄返回的內容是這樣的:
{"status":"1","info":"OK","infocode":"10000","count":"1","geocodes":[{"formatted_address":"北京市朝陽區阜通東大街|6號","province":"北京市","citycode":"010","city":"北京市","district":"朝陽區","township":[],"neighborhood":{"name":[],"type":[]},"building":{"name":[],"type":[]},"adcode":"110105","street":[],"number":[],"location":"116.481229,39.990400","level":"門牌號"}]}
但使用php CRUL 返回的只有:{"status":"1","info":"OK","infocode":"10000","count":"0","geocodes":[]}
geocodes裡面的內容沒有
這是我的php後台代碼片段
$requesturl="http://restapi.amap.com/v3/geocode/geo?address=北京市朝陽區阜通東大街6號&output=json&key=8ca8e28cdd92fed465d899e4798cff39";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $requesturl);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
$info=curl_exec($ch);
curl_close($ch);
echo json_decode($info, true);
你的代碼沒有問題,可以運行並獲得數據,應該是你的文件編碼格式出錯了,你看看你的文件是不是gbk的