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

时间:2016-08-31 08:44:43

标签: google-maps google-api zk

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

在我的应用程序中,我没有使用谷歌API密钥,因为前段时间似乎工作正常(我可以正确地可视化地图)。

从7月份开始,似乎需要使用API​​密钥,因此我尝试插入API密钥。

因此,我按照此https://support.google.com/cloud/answer/6158862?hl=en&ref_topic=6262490的说明为我的应用程序创建了一个浏览器API密钥。然后,按照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而不是地图访问它,我会看到一个带有以下错误消息的灰色框(请注意“接受来自这些HTTP引用者(网站)的请求”)将我的域名插入“* .mydomain.eu /”):

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

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

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.***

关于我能做错什么的任何想法?是否可以使用“浏览器密钥”,还是需要不同类型的密钥?

修改

我尝试将链接标记替换为链接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

3 个答案:

答案 0 :(得分:2)

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

  

加载Google Maps JavaScript API的当前网址尚未添加到允许的引荐来源列表中。请在Google API控制台上查看API密钥的引荐来源设置。

     

API keys in the Google API Console。有关详细信息,请参阅Best practices for securely using API keys

答案 1 :(得分:1)

刚刚发布了新版本的gmaps

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

答案 2 :(得分:0)

您可以尝试以下代码:

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

此外,您必须将API从v2升级到v3。因为谷歌地图到版本2需要API密钥。

详细了解link