【问题标题】:Google Static map without api key gives 403(forbidden) error没有 api 密钥的谷歌静态地图给出 403(禁止)错误
【发布时间】:2017-08-24 19:30:10
【问题描述】:

我正在使用 jspdf 创建 pdf 文档。 在文档中我必须显示谷歌地图,所以我使用了静态谷歌地图https://developers.google.com/maps/documentation/static-maps/intro。 这在 localhost 上运行良好。

但在部署应用程序时出现错误 403(禁止) 我还在静态地图 url 中添加了参数 sensor=false。

请求网址https://maps.googleapis.com/maps/api/staticmap?center=47.3857009,9.2798472&zoom=15&scale=2&format=png&size=600x400&maptype=roadMap&sensor=false&markers=size:mid%7Ccolor:0xff0000%7C47.3857009,9.2798472

谢谢。

【问题讨论】:

    标签: javascript typescript jspdf google-static-maps


    【解决方案1】:

    因为您必须在请求中包含 API 密钥作为参数。没有它,您将无法访问 Google Maps API,因此 403 错误代码明确指出:禁止访问。您甚至提供了一个显示请求示例的文档:

    https://maps.googleapis.com/maps/api/staticmap?center=Brooklyn+Bridge,New+York,NY&zoom=13&size=600x300&maptype=roadmap
    &markers=color:blue%7Clabel:S%7C40.702147,-74.015794&markers=color:green%7Clabel:G%7C40.711614,-74.012318
    &markers=color:red%7Clabel:C%7C40.718217,-73.998284
    &key=YOUR_API_KEY
    

    需要最后一个key 参数才能使其正常工作。

    【讨论】:

    • 确实,自 2016 年 6 月 22 日起,API 密钥是强制性的:maps-apis.googleblog.com/2016/06/…
    • 是的,这是真的.. 但令人惊讶的是,应用程序几天前在没有 API 密钥的情况下工作并突然停止工作.. 这背后的原因可能是什么?你能解释一下吗..
    • 那是因为他们有限制
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-12
    • 1970-01-01
    相关资源
    最近更新 更多