Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Maps Static API returns weird image

Tags:

google-maps

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 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:

Argh

Does anyone know what this image means?

like image 899
Jan Jongboom Avatar asked Dec 22 '22 15:12

Jan Jongboom


2 Answers

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"

like image 138
Argiropoulos Stavros Avatar answered Dec 24 '22 03:12

Argiropoulos Stavros


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);
like image 34
ghstcode Avatar answered Dec 24 '22 03:12

ghstcode