-3

My function below to access googleapi doesnt work all the time in cakephp3. If I run the same function with the same parameters it works mostly but can fail with this error message below. This message does not make sense because if i run the function again it will work . The function is only being run a few times a day only and as i said it works fine most of the time.

[
    '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>
ajt2
  • 37
  • 1
  • 7
  • Did you register for a key? (and add it to your request) – geocodezip May 30 '18 at 02:25
  • no i didnt ask for a key and i thought i was quite clear in the fact i wasnt requiring to run for more than a few times which means i dont need a key. – ajt2 May 30 '18 at 03:39
  • Keys are mandatory, it might work without them, but not (as you discovered) reliably. – geocodezip May 30 '18 at 03:53
  • with that being the case is it really necessary to mark this down? as i dont recall this fact being made public – ajt2 May 30 '18 at 03:56
  • It is in the documentstion – geocodezip May 30 '18 at 04:17
  • where exactly? it is pretty odd to mark down on this basis. where is this in the docs? – ajt2 May 30 '18 at 04:38
  • See also [Geo](https://github.com/dereuromark/cakephp-geo) plugin and the docs about key. – mark May 30 '18 at 12:44
  • Also note that starting from June 11, 2018 Google deprecates keyless access: https://mapsplatform.googleblog.com/2018/05/introducing-google-maps-platform.html – xomena May 30 '18 at 18:42
  • Possible duplicate of [Exceeded usage limits for Geocoding API](https://stackoverflow.com/questions/28962765/exceeded-usage-limits-for-geocoding-api) – Sehdev Jun 12 '18 at 11:24

1 Answers1

0

the api docs say this is a problem with not getting a key

ajt2
  • 37
  • 1
  • 7