来自域名的谷歌地图在谷歌地图中的谷歌API密钥

问题描述:

我有一个使用谷歌地图(gmaps)的ZK(Java Spring)应用程序。我使用的ZK版本是7.0.3 EE。来自域名的谷歌地图在谷歌地图中的谷歌API密钥

在我的应用程序中,我没有使用谷歌API密钥,自从前段时间以来,事情似乎很好(我可以正确地可视化地图)。

看来,自从去年7月以来,API密钥的使用已成为必需,所以我试图插入一个API密钥。

所以,我为我的应用程序创建了一个浏览器API密钥,按照https://support.google.com/cloud/answer/6158862?hl=en&ref_topic=6262490的说明操作。然后,继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> 

发现有了这个,我看到一个白色的盒子,而不是灰色的,以取代script标签,并在JavaScript控制台的错误,现在是Google Maps API error: RefererNotAllowedMapError

+0

您是否尝试过最新版本的gmaps?只是v 3.0.4:https://www.zkoss.org/download/zkgmaps – chillworld

+0

我更新到3.0.4版本,它的工作原理。我非常感谢:请转发此建议作为答案,以便我可以接受 – chrx

gmaps刚刚发布的新版本

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

你可以试试这个代码:

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

此外,您还必须将API从v2升级到v3。因为Google Map最高版本2需要API密钥。

了解更多关于此link的详细信息。

+0

我尝试了您的建议,但不断收到“Google Maps API警告:NoApiKeys”,“Google Maps API警告:SensorNotRequired”和“Google Maps API错误:Javascript控制台中的MissingKeyMapError'错误。 此外,似乎截至2016年6月22日,谷歌地图V3不再支持无钥匙访问。 http://stackoverflow.com/questions/2769148/whats-the-api-key-for-in-google-maps-api-v3 – chrx

+0

我试着改变脚本根据什么建议在我以前链接的线程评论:请参阅帖子上的修改 – chrx

对更新问题的回答可以在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 .