谷歌地图静态API返回奇怪的图像 [英] Google Maps Static API returns weird image

查看:146
本文介绍了谷歌地图静态API返回奇怪的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个以 http://maps.google.com/ ?地图/ API / staticmap大小= 600x240&安培;标记=图标:HTTP://100procentjan.nl/tweakers/punaise.png |阴影:假| 52.369010925293,4.8560848236084&安培;传感器=假安培;变焦= 15&安培;中心= 52.369010925293,4.8560848236084



当我从任何浏览器访问此页面时,它显示得很好,但不是在通过我们的BES连接的Blackberry中使用它时(但同一无线网络! )。然后这张图片显示出来:



p>

有人知道这个图片的含义吗? 这是一个BB Google静态地图API的特定问题。 API速率限制是正常的,但在使用BB设备时它会弹出更多。

它们似乎在使用IP池并将它们转出到设备中。理论上这应该是一个非常间歇性的问题。换句话说,总的来说,您的IP在24小时内将静态地图API命中了1000次以上期。当您在短时间内太频繁地点击API时,也会发生这种情况。

我的解决方案是编写一个简单的PHP脚本,它只需要一次从Google获取地图图片,将其保存为文件,然后直接投放它而不是点击maps API每一次。

以下是代码:

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

Does anyone know what this image means?

解决方案

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);

这篇关于谷歌地图静态API返回奇怪的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆