为什么MissingKeyMapError使用带有质数的标签p:gmap(在最简单的示例中)? [英] Why MissingKeyMapError using tag p:gmap with primefaces (in the simplest example)?

查看:71
本文介绍了为什么MissingKeyMapError使用带有质数的标签p:gmap(在最简单的示例中)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经读到,自Google Maps V3起,开发人员不需要任何api密钥即可使用google map api.我的代码如下(最简单的可视化谷歌地图的代码).我试图在google chrome和Firefox上都运行它,但是在这两个窗口中,地图都弹出了几秒钟,然后应用程序引发了此异常:

I have read that, since Google Maps V3, developers do not need any api key in order to use google map api. My code is the following (the simplest one to visualize a google map). I have tried to run it both on google chrome and on firefox, but in both of them, the map popped up a few seconds and then the app raised this exception:

js?sensor=false:32 Google Maps API error: MissingKeyMapError https://developers.google.com/maps/documentation/javascript/error-messages#missing-key-map-error_.ab @ js?sensor=false:32
util.js:208 Google Maps API warning: NoApiKeys https://developers.google.com/maps/documentation/javascript/error-messages#no-api-keys

代码如下:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui">

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

        <h:body>
            Map:
            <p:gmap center="41.381542, 2.122893" zoom="15" type="HYBRID" style="width:600px;height:400px" />
        </h:body>
    </f:view>

</html>

在primefaces文档中,标签p:gmap没有用于插入api键的属性:

In the documentation of primefaces there's no attribute for tag p:gmap in which insert api keys:

primefaces p:gmap文档

推荐答案

我已经通过如下更改脚本中的源字符串来解决了这个问题:

I have solved this by changing the source string in script as follows:

<script src="http://maps.google.com/maps/api/js?key=MY_API_KEY" type="text/javascript"></script>

这篇关于为什么MissingKeyMapError使用带有质数的标签p:gmap(在最简单的示例中)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆