1

私はこれについて少し混乱しています。

私は店舗ロケーターの緯度と経度を検索しようとしており、Google の Geolocator とそのチュートリアルをhttp://code.google.com/apis/maps/articles/phpsqlgeocode.htmlで使用していますが、うまくいかないようです恐ろしい 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);      

    } 

}     

?>
4

1 に答える 1

0

送信するリクエストが多すぎる可能性があります。

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

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

于 2012-02-17T22:27:19.840 に答える