title: OVER_QUERY_LIMIT for Google Maps API - php to client side
body: <p>We are connecting to <a href="http://maps.googleapis.com/maps/api/geocode/xml" rel="nofollow">http://maps.googleapis.com/maps/api/geocode/xml</a> using a PHP script to geocode a postcode into lon/lat. We are finding that we are constantly hitting the OVER_QUERY_LIMIT status. even though we are storing the postcodes for 1 day.</p>
  
  <p>I would like to look at client side geocoding, but wasn't sure to do it exactly. please can someone take a look at this and see how best to re-write this so that we don't hit the overlimit.</p>
  
  <p>Thanks</p>
  
  <pre><code>&lt;?php
  //database and connection are defined elsewhere
  mysql_select_db($database, $connection);
  
    //check if postcode exists in database
  
    $sqlTS1 = mysql_query("SELECT * FROM  `postcodestable` WHERE `postcode` = UPPER('" . $_GET['postcode'] . "') AND `date_added` &gt;  DATE_SUB(NOW(), INTERVAL 1 DAY)");
    if(mysql_num_rows($sqlTS1)&gt;0) {}
    else
    {     
  
          $postcodeTS1 = strtoupper($_GET['postcode']); // post code to look up 
          $request_url = "http://maps.googleapis.com/maps/api/geocode/xml?address=".$postcodeTS1."&amp;sensor=true";
          $xml = simplexml_load_file($request_url) or die("url not loading");
          $status = $xml-&gt;status;
          if ($status=="OK") 
          {
     //request returned completed time to get lat / lang for storage
              $latTS1 = $xml-&gt;result-&gt;geometry-&gt;location-&gt;lat;
              $longTS1 = $xml-&gt;result-&gt;geometry-&gt;location-&gt;lng;
           }
  
    //insert into postcodes table for server side caching of lon lat
  
          $dateTS1= date('Y-m-d H:i:s');
          $sqlinsert="INSERT INTO postcodestable (postcode,latitude,longitude, date_added) VALUES ('".$postcodeTS1."', '".$latTS1."', '".$longTS1."', '".$dateTS1."')";
          $sqlinserting = mysql_query($sqlinsert) or die(mysql_error());
  
    }
  
  // we can now use $latTS1 and $longTS1 elsewhere within the HTML page
  
  // we then run another script that removes all postcodes from Table where date_added is greater than 1 day.
  
  ?&gt;
  </code></pre>