11
votes

This is using the Static Maps API.

I have a web page with 3 img tags, each of which is a call to the static maps API, (NB of course this is not the real api key).

The 3 tags are identical, except the zoom, which is 10, 13 and 16 for the three images.

The API Key is from a project with the Static maps API enabled, and billing configured and enabled.

I have sent perhaps 60 requests in total (this is a brand new development project, so I'm just getting started).

What I'm seeing is that sometimes, all three maps are displayed. At other times one (random from the three) map fails with

403 "The Google Maps API server rejected your request. An internal error was found for this API project."

So if I refresh the page 5 times, ie 15 requests, I get approx 4 failures and 11 successes.

So why is Google Maps randomly rejecting some of the requests with this 403?

2
link gives: "The Google Maps API server rejected your request. The provided API key is invalid." - Andre Figueiredo
That's because I obfuscated my API key - pinoyyid
I'm not able to replicate but can try look into it. You can file an issue at code.google.com/p/gmaps-api-issues under Static Maps, and be sure to provide (here or there) your numeric project id, confirm that your key you are using ends in JGk, and ensure your contact email in your project is correct. If you're not comfortable sharing your numeric project ID (it is safe to do so) then you need to provide a way I can contact you. - jlivni
Do you get the same error when you exclude the key=API_KEY parameter? - Tyler Eich
@TylerEich without the key it works fine up until I run out of quota when I get the red X map as expected. - pinoyyid

2 Answers

0
votes

Are you sure your API key is correct?

From https://developers.google.com/maps/documentation/staticmaps/#Limits :

The Google Static Maps API has the following usage limits:

  • Without an API key:

    1,000 Static Maps requests per IP address per 24 hour period. 50 Static Maps requests per IP address per minute. This means that if you have a single page containing more than 50 maps, the page will exceed this limit.

Additional image requests can be purchased on a per application basis at the rate currently listed in the FAQ. Additional quota is purchased through the API Console and requires the use of an API key.

If a user exceeds these limits, the server will return an HTTP 403 status and display the below image to indicate that the quota has been exceeded:

403 screenshot

Seems like the 50 maps per minute could explain your random 403 errors.

If this isn't the problem, I would file a support ticket with Google Geo support since it's labelled as "an internal error".

-1
votes

So if I refresh the page 5 times, ie 15 requests, I get approx 4 failures and 11 successes.

I think your requests exceed the limit in short time. I'm not sure how you display the map, but I recommend you load the map serially.

Ex: using JavaScript with https://github.com/caolan/async

<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
    <style type="text/css">
      html,body {
        height: 100%;
        margin: 0;
        padding: 0
      }
    </style>
    <script type="text/javascript" src="async.js"></script>
    <script type="text/javascript">
      function loadImg(params, callback) {
        var url = "http://maps.googleapis.com/maps/api/staticmap?" + 
                   params + "&zoom=1&size=100x100" +
                   "&sensor=false&key={YOUR_KEY_IS_HERE}";
        var img = new Image();
        img.src = url;
        img.onload = function() {
          document.body.appendChild(img);
          callback();
        };
        img.onerror = function() {
          callback(url);
        }
      }

      function loadMaps() {
        var urlList = [
          "markers=label:0|LosAngles",
          "markers=label:1|NewYork",
          "markers=label:2|SanFrancisco",
          "markers=label:3|Frorida",
          "markers=label:4|Arizona",
          "markers=label:5|Ohaio",
          "markers=label:6|Hawai",
          "markers=label:7|Texus",
          "markers=label:8|Seattle",
          "markers=label:9|Florida",
          "markers=label:A|kansas",
          "markers=label:B|utah",
          "markers=label:C|iowa",
          "markers=label:D|oregon",
          "markers=label:E|alaska",
          "markers=label:F|Washington D.C"
        ];

        async.eachSeries(urlList, loadImg, function(err) {
          if (err) {
            console.log("error", err);
          } else {
            console.log("all image are loaded");
          }
        });
      }
    </script>
  </head>
  <body onload="loadMaps()">
  </body>
</html>

enter image description here