为什么我收到第一个请求的 OVER_QUERY_LIMIT 答复?

Why do I receive OVER_QUERY_LIMIT answer of my first request?

我正在使用以下代码根据 Android 应用程序向我的服务器发出的请求获取城市的坐标。:

function getGPSLocation($reqLocation) {

    $url = "http://maps.googleapis.com/maps/api/geocode/json?address=" . $reqLocation . "&sensor=false";
    $attempt = 0;

    $this->log($url, 'debug' );

    $location = [
        'lat' => 0.0,
        'lng' => 0.0
    ];

    while ($attempt < 3) {
        $timeout = 5;
        $ch = curl_init($url);

        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);

        $content = curl_exec($ch);
        $resultHttpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);

        curl_close($ch);

        if ($resultHttpCode == '200') {
            $result = json_decode($content);

            if ($result->status == 'OVER_QUERY_LIMIT') {

                $this->log($result->status, 'debug' );

                sleep(2);
                $attempt ++;

            } else {

                /*
                 * TODO: Store the result to prevent other similar request later.
                 */
                if ($result != null) {
                    $location = $result->results[0]->geometry->location;
                }
                break;
            }
        }
    }
    return $location;

}

此代码在我的本地服务器上完美运行,但从我的在线服务器执行任何请求时,我都会收到 OVER_QUERY_LIMIT 错误。

Google 文档 (https://developers.google.com/maps/documentation/business/articles/usage_limits) 没有告诉我任何可以解释此行为的信息。

有什么想法吗?

在您对 Web 服务的请求中使用密钥,这样 google 可以使您的请求与来自该(我假设)共享服务器的任何其他请求分开。

来自 documentation

API键

Note: Maps for Work users must include client and signature parameters with their requests instead of a key.

All Geocoding API applications should use an API key. Including a key in your request:

Allows you to monitor your application's API usage in the Google Developers Console. Enables per-key instead of per-IP-address quota limits. Ensures that Google can contact you about your application if necessary. The Geocoding API uses an API key to identify your application. API keys are managed through the Google APIs console. To create your key:

Visit the APIs console at Google Developers Console and log in with your Google Account. Click the Services link from the left-hand menu in the APIs Console, then activate the Geocoding API service. Once the service has been activated, your API key is available from the API > Access page, in the Simple API Access section. Geocoding API applications use the Key for server apps. To specify a key in your request, include it as the value of a key parameter.

Note: By default, a key can be used from any server. We strongly recommend that you restrict the use of your key by IP address to servers that you administer. You can specify which IP addresses are allowed to use your API key by clicking the Edit allowed referers... link in the API console.

Note: HTTPS is enforced for requests that include an API key.