谷歌地图静态图像API作为背景图像?

时间:2014-12-06 17:53:15

标签: css google-maps background-image

我尝试使用静态Google地图作为内联CSS背景图片。

我特指这个API:https://developers.google.com/maps/documentation/staticmaps/

当我自己调用图片时,在实际的img标记中,它完美无缺。将它添加为CSS背景图像,它没有。我找不到任何文件说它不应该工作。

以下是我使用的代码:

<div class="static-map" style="background:url('https://maps.googleapis.com/maps/api/staticmap?center=Hollywood, FL, USA&zoom=7&size=420x200&maptype=roadmap
&markers=color:red%7C26.0112014,-80.14949009999998') no-repeat; background-size:cover;">

有没有人知道使用动态查询图像是否有限制?如果您直接转到该网址,则会看到图片:https://maps.googleapis.com/maps/api/staticmap?center=Hollywood,%20FL,%20USA&zoom=7&size=420x200&maptype=roadmap%20&markers=color:red%7C26.0112014,-80.14949009999998

更新我已将其缩小到网址的&markers=color:red%7C26.0112014,-80.14949009999998部分。可能是:具体,但编码不起作用......

1 个答案:

答案 0 :(得分:0)

我想通了 - 除了我上面粘贴的代码之外,我还有一个附加到URL的API密钥(由于显而易见的原因我不想分享)。

但Google似乎不允许您将localhost环境与API密钥相关联,因此拒绝了该请求。

放弃API密钥直到它进入生产服务器是我能想到的唯一解决方案。

相关问题