2012-02-17 4 views
1

これについて少し混乱します。google geolocator:直接URLが機能し、simplexml_load_fileを使用している場合はステータスコード620が表示されます

私はラッツにストアロケータの& lngsを検索しようとしているとhttp://code.google.com/apis/maps/articles/phpsqlgeocode.htmlでGoogleのGeolocatorとそのチュートリアルで取り組んできましたが、恐ろしい620あまりにも多くのクエリエラー以外のものを返すように見えることはできません。

私の$ request_urlをブラウザにコピーすると、期待どおりのXMLがすべて得られますが、PHPのsimplexml_load_file($ request_url)を使用すると、遅れてもエラーコード620が返されます。どのように多くの異なるAPIキーを使用しています。

誰もがこれを知っていますか?恐ろしい間違いをしていますか?あなたが最も可能性が高いが速すぎる、あまりにも多くのリクエストを送信している

<?php 

$host = 'xxx'; 
$db = 'xxx'; 
$u = 'xxx'; 
$p = 'xxx'; 

define("MAPS_HOST", "maps.google.com"); 
define("KEY", "xxx"); 

// Opens a connection to a MySQL server 
$connection = mysql_connect($host, $u, $p); 
if (!$connection) { 
    die("Not connected : " . mysql_error()); 
} 

// Set the active MySQL database 
$db_selected = mysql_select_db($db, $connection); 
if (!$db_selected) { 
    die("Can\'t use db : " . mysql_error()); 
} 

// Select all the rows in the markers table 
$query = "SELECT * FROM BH_locations"; 
$result = mysql_query($query); 
if (!$result) { 
    die("Invalid query: " . mysql_error()); 
} 

// Initialize delay in geocode speed 
$delay = 0; 
$base_url = "http://" . MAPS_HOST . "/maps/geo?output=xml" . "&key=" . KEY; 

// Iterate through the rows, geocoding each address 
while ($row = @mysql_fetch_assoc($result)) { 
    echo '<br /><br />row#' . $row['id'] . '<br />'; 

    $geocode_pending = true; 

    while ($geocode_pending) {  
     echo 'started while loop at ' . date('G:i:s:u') . '<br />'; 
     $address = $row["address"] . ', ' . $row['city'] . ', ' . $row['state'] . ' ' . $row['zip']; 
     echo $address . '<br />';  

     $id = $row["id"]; 
     $request_url = $base_url . "&q=" . urlencode($address);  
     echo 'request url: ' . $request_url . '<br />'; 
     $xml = simplexml_load_file($request_url) or die("url not loading"); 
     echo '<pre>'; 
     var_dump($xml); 
     echo '</pre>'; 

     $status = $xml->Response->Status->code; 

     if (strcmp($status, "200") == 0) { 
      // Successful geocode 
      echo '<br /><strong>WOOHOO IT WORKED!!!</strong><br />'; 
      $geocode_pending = false; 


      /* 
      $coordinates = $xml->Response->Placemark->Point->coordinates; 
      $coordinatesSplit = split(",", $coordinates); 
      // Format: Longitude, Latitude, Altitude 
      $lat = $coordinatesSplit[1]; 
      $lng = $coordinatesSplit[0]; 

      $query = sprintf("UPDATE BH_locations " . 
       " SET latitude = '%s', longitude = '%s' " . 
       " WHERE id = '%s' LIMIT 1;", 
       mysql_real_escape_string($lat), 
       mysql_real_escape_string($lng), 
       mysql_real_escape_string($id)); 
      $update_result = mysql_query($query); 
      if (!$update_result) { 
       die("Invalid query: " . mysql_error()); 
      } 
      */ 



     } else if (strcmp($status, "620") == 0) { 
      // sent geocodes too fast 
      $delay += 100000;  
      echo 'error 620<br /><br />'; 
     } else { 
      // failure to geocode 
      $geocode_pending = false; 
      echo "Address " . $address . " failed to geocoded. "; 
      echo "Received status " . $status . "\n"; 
     } 

     usleep($delay);  

    } 

}  

?> 
+0

あなたは '$ request_url'を提供できますか?ジオコーディングは1つだけですか?あなたは1つのエラー(620)だけを見ますか?またはあなたの成功したメッセージのいくつかが見えますか? – Josh

+0

おっと、申し訳ありませんが、データの量を指定していません - それは約350のアドレスです。それは私のサーバーがタイムアウトするまで、拳の1つを過ぎることはありません、ちょうど620エラーを何度も繰り返します。 request_urlはhttp://maps.google.com/maps/geo?output=xml&key=[MY APIキー]&q = [住所] – jabram

+1

です。万が一共有ホストにいますか?これは現時点ではドキュメントには記載されていないようですが、要求の制限を超えた場合のIP単位の制限とIP単位の禁止について、インターネット上の参照があります。共有ホストでは、これはかなり可能性があり、ブラウザのアドレスバーにURLを貼り付けると(IPと共有ホストのIPと考える)、失敗しない理由を説明します。 – bububaba

答えて

0

私のコードでは、大規模なコメントやエコーを言い訳してください、以下の通りです。

GoogleマップのドキュメントのG_GEO_TOO_MANY_QUERIES定数を参照してください。

の24時間以内に所定のキーが要求制限を超えているか、あまりにも多くのリクエストをあまりにも短時間で送信しました。 並列またはタイトループで複数のリクエストを送信する場合は、タイマーを使用するかコード内で一時停止して、 リクエストをあまりにも速く送信しないようにします。

関連する問題