【发布时间】:2015-09-23 14:02:10
【问题描述】:
需要获取纬度和经度的位置详细信息, 它只是在其他服务器上工作 - 正常运行,但尝试客户端开发服务器出错,我已经尝试了大约 4 个小时 - 直到没有得到结果。协助会有所帮助。 这是我的代码:
public function index() {
echo $this->getLocation('39.2323', '-97.3828');
}
function getLocation($lat, $long) {
$url = "http://maps.googleapis.com/maps/api/geocode/json?latlng=" . trim($lat) . "," . trim($long) . "&sensor=false";
$json = @file_get_contents($url);
$data = json_decode($json);
$status = $data->status;
$address = '';
if ($status == "OK") {
$address = $data->results[0]->formatted_address;
}
return $address;
}
收到如下错误:
遇到 PHP 错误 严重性:警告消息: file_get_contents(http://maps.googleapis.com/maps/api/geocode/json?latlng=39.2323,-97.3828&sensor=false) [function.file-get-contents]:无法打开流:连接计时 出去
文件名:webservice/Test.php 行号:17
回溯:
文件: /home/colanful/public_html/hoa/application/controllers/webservice/Test.php 行:17 函数:file_get_contents
文件: /home/colanful/public_html/hoa/application/controllers/webservice/Test.php 行:12 功能:getaddress
文件:/home/colanful/public_html/hoa/index.php 行:292 功能: 需要一次
【问题讨论】:
标签: php codeigniter google-maps curl file-get-contents