Google API 来自域名的 ZK 应用程序中 Google 地图的密钥

Google API Key for Google Maps in ZK Application from domain name

我有一个使用 Google 地图 (gmaps) 的 ZK (Java Spring) 应用程序。我用的ZK版本是7.0.3 EE.

在我的应用程序中,我没有使用 google API 键,而且从前一段时间开始一切似乎都运行良好(我可以正确地可视化地图)。

似乎从去年 7 月开始就需要使用 API 密钥,所以我尝试插入一个 API 密钥。

所以,我为我的应用程序创建了一个浏览器 API 密钥,按照此处的说明 https://support.google.com/cloud/answer/6158862?hl=en&ref_topic=6262490. Then, following the example at https://www.zkoss.org/zkdemo/reporting/google_map 我在我的 .zul 页面中添加了以下标签:

<script type="text/javascript" content="zk.googleAPIkey='my api key'" />
<gmaps ...> 
</gmaps>

请注意,如果我从本地 IP 访问 Web 应用程序,地图会正确显示。另一方面,如果我通过注册域名 portal.mydomain.eu 而不是地图访问它,我会看到一个带有以下错误消息的灰色框(请注意,在 "Accept requests from these HTTP referrers (web sites)" 中我将我的域名插入为“* .mydomain.eu/"):

Oops! Something went wrong.
This page didn't load Google Maps correctly. See the JavaScript console for technical details.

以下是 Java 脚本控制台错误消息(这些消息是意大利语的,我在每行下面的相关位置插入了英文翻译):

GET 
http://portal.mydomain.eu/images/portal_footer.jpg [HTTP/1.1 404 Not Found 23ms]
L’API Fullscreen con prefisso è deprecata, al suo posto utilizzare l’API senza prefisso. Per ulteriori informazioni consultare https://developer.mozilla.org/en-US/docs/Web/API/Fullscreen_API controls.js:23:54
***the Fullscreen API with prefix is deprecate, use insteass the API without a prefix. For further information ... ***

"Google Maps API error: MissingKeyMapError https://developers.google.com/maps/documentation/javascript/error-messages#missing-key-map-error" js:35:350
"Google Maps API warning: NoApiKeys https://developers.google.com/maps/documentation/javascript/error-messages#no-api-keys" util.js:221:12
"Google Maps API warning: RetiredVersion https://developers.google.com/maps/documentation/javascript/error-messages#retired-version" util.js:221:12
"Google Maps API warning: SensorNotRequired https://developers.google.com/maps/documentation/javascript/error-messages#sensor-not-required" util.js:221:12
"Google Maps API warning: InvalidClientId https://developers.google.com/maps/documentation/javascript/error-messages#invalid-client-id" util.js:221:12
L’utilizzo di getPreventDefault() è deprecato. Al suo posto utilizzare defaultPrevented.
***the usage of getPreventDefault() is deprecated. Use instead defaultPrevented.***

知道我做错了什么吗?可以使用 "Browser Key" 还是我需要不同类型的密钥?

编辑:

我尝试用在 link Whats the API Key for in Google Maps API V3?

中找到的脚本标签替换
<script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY" type="text/javascript"></script>

有了这个,我看到一个白色框而不是灰色框,并且在 javascript 控制台上,错误现在是 Google Maps API error: RefererNotAllowedMapError

您可以试试这个代码:

<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"/> <gmaps>....</gmaps>

您还必须将 API 从 v2 升级到 v3。因为 Google 映射到版本 2 需要 API 密钥。

获取有关此内容的更多详细信息link

刚刚发布了新版 gmaps

试试这个版本:3.0.4。 https://www.zkoss.org/download/zkgmaps

您可以在 documentation 上找到您对更新问题的回答。基本上,RefererNotAllowedMapError 表示加载 API 的 URL 未添加到引荐来源列表。

The current URL loading the Google Maps JavaScript API has not been added to the list of allowed referrers. Please check the referrer settings of your API key on the Google API Console.

See API keys in the Google API Console. For more information, see Best practices for securely using API keys.