2016-12-01 81 views
-1

我已经使用下面给出的代码来获取计算两地之间驾驶距离的地方的经度和纬度。在两个地方之间的驾驶距离在PHP不起作用

function get_coordinates($city, $street, $province) 
{ 
$address = urlencode($city.','.$street.','.$province); 
$url = "http://maps.google.com/maps/api/geocode/json?address=$address&sensor=false&region=Poland"; 
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_PROXYPORT, 3128); 
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); 
$response = curl_exec($ch); 
curl_close($ch); 
$response_a = json_decode($response); 
$status = $response_a->status; 
if ($status == 'ZERO_RESULTS') 
{ 
    return FALSE; 
} 
else 
{ 
    $return = array('lat' => $response_a->results[0]->geometry->location->lat, 'long' => $long = $response_a->results[0]->geometry->location->lng); 
    return $return; 
} 

}

我不明白这一点。它显示一个空数组。当echo $状态时,我得到'OVER_QUERY_LIMIT'。 此代码在godaddy服务器中完美工作。 Iam在我将其更改为网络解决方案服务器时遇到这些错误。 如何解决这个问题?

感谢

回答

0

错误OVER_QUERY_LIMIT意味着你已用尽的一天API的使用。

这里的解释是:每天

2500个免费申请,为客户端和服务器端的查询的总和。

每秒50个请求,计算为客户端和服务器端查询的总和。

Google Usage Limits

可以产生一些API密钥按照您的要求,并用尽时,切换他们。

Generate API Key from Google Console

希望这有助于!

+0

但它是在另一台服务器使用相同的API – Ranju

+0

这是因为IP地址。 Google通过IP跟踪API限制。您的本地IP与服务器的IP不同。本地和服务器上的API使用已经耗尽,但仍有剩余使用量。 – Samir

+0

一个是我们公司的服务器是godaddy,另一个是客户端是网络解决方案。 thia正在godaddy.but而不是在网络解决方案中工作。 – Ranju

相关问题