缺少自定义标记......有时

Custom marker missing ... sometimes

我们正在使用静态 google 地图 API 一切正常,但突然间我们的自定义标记图标开始出现问题。有时它会按预期显示,有时我们会以默认标记和右上角的黄色横幅告终:"Map error: g.co/staticmaperror".

查看 headers 我们发现 google 在获取我们的标记图像时似乎有问题:

x-staticmap-api-warning: Failed to fetch image url https://www.xyz.de/some_image.png

我可以发出 n 次相同的请求,并得到一些 m <= n 个正常的响应和一些 o <= n 个具有上述问题的请求。在我看来,google 在缓存图像时遇到了一些问题。
不过,我从我们的服务器请求标记图像没有问题。没有触发的防火墙规则。标记图像有一个高 cache-control max-age 和一个很好的 etag,它 expires 两周后。没什么好看的。

地图请求如下所示:

https://maps.googleapis.com/maps/api/staticmap?key=<OUR_KEY>&size=260x130&maptype=roadmap&format=png&visual_refresh=true&zoom=10&markers=icon:https://www.xyz.de/some_image.png|52.52008961%2C13.40465566&signature=<SIG>

这里也没什么特别的。

既然 SO 现在似乎是官方 google 支持,请一些 google 技术人员帮忙?

您似乎受到了 this issue 的影响,Google 的问题跟踪器大约一个月前报告了该问题,此后已修复。

如果您有时仍然遇到 "failed to fetch image url" 错误,我建议您对该错误发表评论,以便 Google 技术人员可以从他们的角度进一步调查。

希望对您有所帮助!

事实证明,我们的应用程序防火墙实际上阻止了来自 Google 的一些请求,我们必须添加更多规则。 (虽然我们认为我们已经检查了两次。)

遗憾的是,地图服务没有固定的 IP 范围。但让我与您分享一下支持人员告诉我的内容:


Google Cloud Support

It is not possible to provide a specific list of IP addresses that must be accessible in order to use the Maps APIs, because Google services are not tied to specific hosts or IP addresses in our data centers.

Services are migrated between data centers depending on load, maintenance schedules, and growth. The particular data center that a specific request is routed to depends on the user's geographical location, network location, and the relative load on nearby data centers currently hosting the service concerned, and on the network links that connect them.

If you need to add IP based firewall rules, your only option is to whitelist Google's entire network allocation, which can be obtained using the following command from a Unix system:

$ dig +short _spf.google.com txt

The answer will include some text like:

"v=spf1 include:_netblocks.google.com include:_netblocks2.google.com include:_netblocks3.google.com ~all"

Be sure to follow the includes for all the netblocks e.g.

$ dig +short _netblocks.google.com txt

$ dig +short _netblocks2.google.com txt

$ dig +short _netblocks3.google.com txt

The answer section lists all IP address blocks in CIDR notation.

This list changes several times a year as servers are added and removed, and it is your responsibility to track those changes and update your firewall accordingly. (We recommend that you do so every quarter).

In general it is much easier to set firewall rules based on the list of hostnames used by the Maps API, which is more stable.


修复的另一种方法是对此静态资源(标记图标)进行例外处理。