Why MissingKeyMapError using tag p:gmap with primefaces (in the simplest example)?

痞子三分冷 提交于 2019-12-23 05:03:40

问题


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

The code is the following:

<?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>

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

primefaces p:gmap documentation


回答1:


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>


来源:https://stackoverflow.com/questions/38220868/why-missingkeymaperror-using-tag-pgmap-with-primefaces-in-the-simplest-example

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!