无法解析主机 'maps.googleapis.com 问题在 Google 反向地理编码中随机发生
我尝试使用 PHP 进行谷歌反向地理编码。如果我第一次运行 PHP,它会完美地返回格式化地址,再次重新加载 PHP 意味着它会返回,Curl 错误:无法解析主机 'maps.googleapis.com'
如果我再次运行该地址PHP它正确返回地址...这意味着它随机工作...
我搜索了这个错误,都说它是DNS问题,所以联系DNS提供商...但他们说他们这边没有问题...
我尝试在查询之间延迟时间(睡眠功能)最多 60秒..但这也不起作用,延迟 60 秒后会出现相同的错误....
我的 PHP 代码:
<?php
//sleep(60);
$url='http://maps.googleapis.com/maps/api/geocode/json?latlng=11.49731013,77.24445245&sensor=false';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_REFERER, 'http://www.mysite.com/dns.php');
$body = curl_exec($ch);
if($body=== false) {
echo "<br>";
echo 'Curl error: ' . curl_error($ch);
echo "<br>";
}
else
{
$json = json_decode($body);
$addr2=$json->results[0]->formatted_address;
echo "<br>";
echo $addr2;
echo "<br>";
}
?>
我的编码中有什么问题吗....请帮我解决这个问题...
i tried Google reverse geocoding using PHP. If i run my PHP for first time it returns formatted address perfectly, again i reload the PHP means it returns , Curl error: Couldn't resolve host 'maps.googleapis.com'
If i again run that PHP it return address properly...That means it works randomly....
I search about this error, all said it DNS Problem, so contact DNS provider...But they said there is no problem in their side...
I tried time delay(sleep function) in between queries upto 60 seconds..but that also not works same error occurs after 60 sec delay....
My PHP Code:
<?php
//sleep(60);
$url='http://maps.googleapis.com/maps/api/geocode/json?latlng=11.49731013,77.24445245&sensor=false';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_REFERER, 'http://www.mysite.com/dns.php');
$body = curl_exec($ch);
if($body=== false) {
echo "<br>";
echo 'Curl error: ' . curl_error($ch);
echo "<br>";
}
else
{
$json = json_decode($body);
$addr2=$json->results[0]->formatted_address;
echo "<br>";
echo $addr2;
echo "<br>";
}
?>
is it any problem in my coding....please help me solve this problem...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以将maps.googleapis.com 添加到服务器的主机文件中,或者,如果您无权访问该文件,请连接到该地址解析到的IP 地址。另一种方法是缓存maps.googleapis.com 解析到的IP 地址,然后在使用FQDN 超时时使用该缓存的IP 地址进行连接。
You could just add maps.googleapis.com to your server's hosts file, or, if you don't have access to that, connect to the IP address the address resolves to instead. Even another way would be to cache the IP address that maps.googleapis.com resolves to, and then use that cached IP address to connect in the event you get a timeout from using the FQDN.