2014-07-04 6 views
0

http://maps.googleapis.com/maps/api/geocode/xml에 PHP 스크립트를 사용하여 우편 번호를 lon/lat로 지오 코딩합니다. 우리는 OVER_QUERY_LIMIT 상태를 지속적으로 유지하고 있습니다. 우리가 1 일 동안 우편 번호를 저장하더라도.Google지도 API - 클라이언트 측 OVER_QUERY_LIMIT

클라이언트 쪽 지오 코딩을 살펴보고 싶지만 정확하게 설명하지는 않았습니다. 제발 누군가가 이것 좀 봐하고 우리가 overimit을 치지 않도록 이걸 다시 쓰는 것이 가장 좋은 방법을 볼 수 있습니다.

감사

<?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. 

?> 
+0

클라이언트 측은 일반적으로 자바 스크립트를 사용하여 호출을 처리하는 것을 의미합니다. 따라서 서버 측 코드 – islanddave

+0

보다는 html/js에 요청을 추가해야합니다. 내가 시도하고 지리 코드 자바 스크립트에 대한 검색 후 PHP로 변수를 변환합니다. 나는 php로 괜찮지 만 자바 스크립트가 아니다. –

+0

한계 문제를 극복하기 위해 노력하지 않을 것이다. 모든 PHP는 서버 측에서 실행됩니다. JS는 클라이언트 측에서 실행됩니다 (사용자 브라우저에서는 서버에서 실행되지 않음). GMaps는 그 차이를 안다. – islanddave

답변

0

좋아, 나는 주위에 모양과이 컴파일 ... 다음

<?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()); 
?> 

그건 ... 그건 매력처럼 작동합니다.

감사합니다.

관련 문제