0

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

StackUser
  • 587
  • 6
  • 26
  • so how do you know your PrimeFaces version (which one?) uses the gmap V3 api? – Kukeltje Jul 06 '16 at 19:09
  • Google Maps API JS now requires a key: http://googlegeodevelopers.blogspot.ch/2016/06/building-for-scale-updates-to-google.html. – kaskader Jul 06 '16 at 22:02
  • Thank you guys. Anyway, in the docuemntation of primefaces there's no attribute for tag p:gmap to insert api keys: http://www.primefaces.org/docs/vdl/3.4/primefaces-p/gmap.html – StackUser Jul 07 '16 at 10:40
  • So you are using PrimeFaces 3.4? Does the newer versions include it? – Kukeltje Jul 07 '16 at 11:26

1 Answers1

4

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>
Egel
  • 1,796
  • 2
  • 24
  • 35
StackUser
  • 587
  • 6
  • 26