这个代码我用来查找地点的纬度和经度:
function coords($address){
echo $url="http://maps.googleapis.com/maps/api/geocode/json?address=".$address;
$json = file_get_contents(urlencode($url));
$data = json_decode($json, TRUE);
print_r($data['results'][0]['geometry']['location']['lat']);
print_r($data['results'][0]['geometry']['location']['lng']);
}
Run Code Online (Sandbox Code Playgroud)
但是它总是返回此警告:
无法打开流:HTTP请求失败!HTTP/1.0 400错误请求
如果我在一个简单的过程中使用上面的代码它工作正常但不在函数中.
注意:我试过curl_init()...产生相同结果的方法?