<iframe width="100%" height="427" frameborder="0" style="border:0" src="https://www.google.com/maps/embed/v1/place?q=place_id:[place_id]&key=[my_key]" allowfullscreen></iframe>
"谷歌地图平台拒绝了你的请求。此 IP、站点或移动应用程序无权使用此 API 密钥。从 IP 地址 xxx.xxx.xxx.xxx 收到的请求,引用者:https://xxx.xxx/">
在Google Dev中,我启用了Maps Embedded API和Maps Static API。我将密钥限制为仅适用于我的域,其中包含上述代码,例如 https://[asterisk].thedomain.com/[asterisk]。
地图嵌入工作并且不会抛出错误,当我不将密钥限制在这个单一域时。
问题是,密钥在代码中是可读的,因此我需要将密钥限制在我的域中。
有什么想法吗?
谢谢。
我有问题的网站像 https://thedomain.com/一样交付。
谷歌地图平台确实在 https://www.thedomain.com/和 https://thedomain.com/之间有所不同。
将我的 API 限制为https://thedomain.com/*
对我有用,而https://*.thedomain.com/*
并不意味着 * 什么都不是。
确保您已将"映射嵌入式 API"添加到您正在使用的 API 密钥的密钥限制/API 限制部分。
如果你检查谷歌给出的例子,它是一个错误。它应该是:http://*example.com/* 而不是 http://*.example.com/*,因为如果你的域名之前没有像 www 这样的东西,它就不起作用。
http://example.com 不会工作,因为它在//
和example
之间没有.
。