开发者

Google Maps Static API returns weird image

I have a page that has a static maps URI in the form of http://maps.google.com/maps/api/staticmap?size=600x240&markers=icon:http://100procentjan.nl/tweakers/punaise.png|shadow:false|52.369010925293,4.8560848236084&sensor=false&zoom=15&center=52.369010925293,4.8560848236084 .

When I visit this page from any browser it shows 开发者_JAVA技巧up just fine, but not when I use it through a Blackberry that is connected through our BES (but same wireless network!). Then this image shows up:

Google Maps Static API returns weird image

Does anyone know what this image means?


You have exceeded the usage limits for the specific ip address

"Use of the Google Static Maps API is subject to a query limit of 1000 unique (different) image requests per viewer per day"


This is a BB specific issue with Google's static maps API. The API rate limit is normal, but it pops up more often when using BB devices.

They seem to be using an IP pool and rotating those out to devices. This should in theory be a very intermittent issue. If you wait a few days hours, it should go away.

In other words, collectively, your IP has hit the static maps API more than 1000 times in a 24 hours period. This also happens when you hit the API too frequently within a short space of time.

My solution to this was to write a simple PHP script that requested the map image from Google once, saved it as a file and just served it instead of hitting the maps API each time.

Here's the code:

<?php

header('Content-Type: image/jpeg');

$latlng = (isset($_GET['c']))? $_GET['c'] : NULL ;
$zoom   = (isset($_GET['z']))? $_GET['z'] : 9 ;
$file   = "cache/p_$p-z_$zoom.jpg";

if(!file_exists($file))
{
    $parts = array(
        'center'  => $latlng,
        'zoom'    => $zoom,
        'size'    => '320x240',
        'maptype' => 'terrain',
        'sensor'  => 'false',
        'format'  => 'jpeg'
    );      

    file_put_contents(
        $file, file_get_contents("http://maps.googleapis.com/maps/api/staticmap?".implode('&', $parts))
    );
}

echo file_get_contents($file);


I was having this same issue on various wireless carriers. I believe it was due to having many users worth of traffic funnel through the same external IP address used by the wireless carrier. Google sees these all as a single request source.

To fix, make sure you are appending your Google API key to the end of your request for the static map. Example:

http://maps.googleapis.com/maps/api/staticmap?center=<lat>,<lng>&zoom=17&markers=color:0059A9%7C<lat>,<lng>&size=576x174&sensor=false&key=YOUR_SUPER_LONG_GOOGLE_API_KEY_GOES_HERE


I get this too, always, on a Blackberry. Don't think its usage limits, because I just woke up, and my total accesses = 1. Unless its some shared IP issue related to Blackberry.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜