繁体   English   中英

适用于Google Maps API的OVER_QUERY_LIMIT-通过PHP连接到客户端

[英]OVER_QUERY_LIMIT for Google Maps API - php to client side

我们正在使用PHP脚本将http://maps.googleapis.com/maps/api/geocode/xml连接到lon / lat。 我们发现我们一直在达到OVER_QUERY_LIMIT状态。 即使我们将邮政编码存储1天。

我想看一下客户端的地理编码,但不确定是否完全做到这一点。 请有人可以看看这个,看看如何最好地重写它,这样我们才不会超出上限。

谢谢

<?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` >  DATE_SUB(NOW(), INTERVAL 1 DAY)");
  if(mysql_num_rows($sqlTS1)>0) {}
  else
  {     

        $postcodeTS1 = strtoupper($_GET['postcode']); // post code to look up 
        $request_url = "http://maps.googleapis.com/maps/api/geocode/xml?address=".$postcodeTS1."&sensor=true";
        $xml = simplexml_load_file($request_url) or die("url not loading");
        $status = $xml->status;
        if ($status=="OK") 
        {
   //request returned completed time to get lat / lang for storage
            $latTS1 = $xml->result->geometry->location->lat;
            $longTS1 = $xml->result->geometry->location->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.

?>

好吧,我环顾四周并编译了这个...

<?php
    mysql_select_db($database, $connection);

    $sqlTS1 = mysql_query("SELECT * FROM  `postcodestable` WHERE `postcode` = UPPER('" . $_GET['postcode'] . "')");
    if(mysql_num_rows($sqlTS1)>0) {echo "postcode is already in database";}
else { $postcode1 = strtoupper($_GET['postcode']);
?>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false;key=MYAPIKEY"></script>
<script type="text/javascript">
<!--
    function GetLocation() {
        var geocoder = new google.maps.Geocoder();
        var postcode = <?php echo json_encode($postcodeTS1); ?>;;
        geocoder.geocode({ 'address': postcode }, function (results, status) {
            if (status == google.maps.GeocoderStatus.OK) {
                var latitude = results[0].geometry.location.lat();
                var longitude = results[0].geometry.location.lng();

        $.post("insert.php",
          { postcode1: postcode, lat1: latitude, long1: longitude },
             function(data){
             }
          );
            } else {
            }
        });
    };
    //-->

    window.onload = GetLocation;
    </script>

    <?php
echo "postcode is not in database"; }
?>

然后我有insert.php文件,如果没有在数据库中,它将插入邮政编码。

<?php
    if (isset($_POST["postcode1"])) {
    mysql_select_db($database, $connection);
    $postcode2 = $_POST['postcode1'];
    $lat2 = $_POST['lat1'];
    $long2 = $_POST['long1'];
    $date2= date('Y-m-d H:i:s');
    $sqlinsert="INSERT INTO postcodestable (postcode, latitude, longitude, date_added) VALUES ('".$postcode2."', '".$lat2."', '".$long2."', '".$date2."')";
        $sqlinserting = mysql_query($sqlinsert) or die(mysql_error());
    }
?>

在网站的其他地方,我会清理旧的邮政编码,如果它们太旧了,以免使我的桌子膨胀。

<?php 
    mysql_select_db($database, $connection);
    $sql = "DELETE FROM postcodestable WHERE date_added < DATE_SUB(NOW(), INTERVAL 24 HOUR)";

    $result = mysql_query($sql) or die( "An error has ocured: " .mysql_error (). ":" .mysql_errno ());
?>

就是这样...它就像一种魅力。

感谢您的指导。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM