【发布时间】:2018-05-30 02:10:06
【问题描述】:
我下面访问 googleapi 的功能在 cakephp3 中一直不起作用。如果我使用相同的参数运行相同的函数,它通常可以工作,但可能会在下面出现此错误消息而失败。此消息没有意义,因为如果我再次运行该功能,它将起作用。该功能每天只运行几次,正如我所说,它大部分时间都运行良好。
[
'error_message' => 'You have exceeded your daily request quota for this API. We recommend registering for a key at the Google Developers Console: https://console.developers.google.com/apis/credentials?project=_',
'results' => [],
'status' => 'OVER_QUERY_LIMIT'
]
private function calculate_test($suburb=null,$state=null){
$state='VIC';
$country='AU';
if ( $suburb==null){
return 0;
}
$address = $suburb.','.$state.','.$country;
$array = array();
$url = "http://maps.googleapis.com/maps/api/geocode/json?address=".urlencode($address )."&sensor=false";
$result_string = file_get_contents($url);
$geo2 = json_decode($result_string, true);
debug('$geo2');
debug($geo2);
if ($geo2['status'] == 'OK') {
if (isset($geo2['results'][0]['geometry']['location']['lat']) && isset($geo2['results'][0]['geometry']['location']['lng'])){
$lat=$geo2['results'][0]['geometry']['location']['lat'];
$long=$geo2['results'][0]['geometry']['location']['lng'];
$array = array('suburb'=> $suburb ,'lat'=> $lat, 'long'=> $long);
}
}
return $array;
}
in layout i have the entry
<script type="text/javascript" src="https://maps.google.com.au/maps/api/js?sensor=false"></script>
【问题讨论】:
-
您注册了密钥吗? (并将其添加到您的请求中)
-
不,我没有要钥匙,我认为我很清楚,我不需要运行超过几次,这意味着我不需要钥匙。
-
密钥是强制性的,没有它们它可能会工作,但不是(如您所发现的)可靠。
-
既然如此,真的有必要把它标记下来吗?因为我不记得这个事实被公开了
-
在文档中
标签: google-maps cakephp