我在下面访问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>
答案 0 :(得分:0)
api文档说这是一个没有获得密钥的问题