使用代理 php 进行地理编码
我是新人,我正在使用地图 api 来地理编码地址。在我的机器上没有任何问题。问题是当我有一个带有代理的服务器时。我尝试使用两个不同的函数配置代理:
function curl($url)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_PROXY, "http://my_proxy");
curl_setopt($ch, CURLOPT_PROXYPORT, my_port);
curl_setopt($ch, CURLOPT_HEADER,0); //Change this to a 1 to return headers
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER["HTTP_USER_AGENT"]);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($ch);
var_dump($data);
curl_close($ch);
return $data;
}
或者
function curl($url)
{
$opts = array('http' => array('proxy' => 'tcp://my_proxy', 'request_fulluri' => true));
$context = stream_context_create($opts);
$data = file_get_contents($url, false, $context);
return $data;
}
然后我使用这些行调用该函数:
$address = urlencode($address);
$data = $this->curl("http://maps.google.com/maps/api/geocode/xml?address={$address}&sensor=false");
$lat_lng = simplexml_load_string($data);
但我收到“OVER_QUERY_LIMIT”错误。
你有什么想法吗? 谢谢。
I'm new and I'm using maps api to geocode address. In my machine I don't have any problem. The problem is when I have a server with proxy. I tried to configure the proxy using two different functions:
function curl($url)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_PROXY, "http://my_proxy");
curl_setopt($ch, CURLOPT_PROXYPORT, my_port);
curl_setopt($ch, CURLOPT_HEADER,0); //Change this to a 1 to return headers
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER["HTTP_USER_AGENT"]);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($ch);
var_dump($data);
curl_close($ch);
return $data;
}
or
function curl($url)
{
$opts = array('http' => array('proxy' => 'tcp://my_proxy', 'request_fulluri' => true));
$context = stream_context_create($opts);
$data = file_get_contents($url, false, $context);
return $data;
}
and then I'm calling that function using these lines:
$address = urlencode($address);
$data = $this->curl("http://maps.google.com/maps/api/geocode/xml?address={$address}&sensor=false");
$lat_lng = simplexml_load_string($data);
but I'm getting 'OVER_QUERY_LIMIT' error.
Do you have any idea?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
听起来该代理已被许多其他人使用,其中一个人已经超出了(大约每天 1000 个?)查询限制。
It sounds like the proxy is used by many other people, and one of them has already exceeded the (~1000-a-day?) query limit.