It does not load the google map having created an api in google api console

0

I have registered an Api to insert a Google map but I do not upload the map on the web.

I get the error in the console:

  

InvalidValueError: initialise is not a function.

<script src="http://maps.googleapis.com/maps/api/js?key=AIzaSyAbAymW3TTBTkQ-vDS-8r3nvBxVnWlfqcY&sensor=false&region=ES&callback=initialise"></script>
<script type="text/javascript">
function initialise() {
  var coordenadas = new google.maps.LatLng(38.959777, -3.886762); 
  var colores = [{
    featureType: "all", 
    elementType: "all", 
    stylers: [
      {saturation: -100},
      {lightness:0}, 
      {invert_lightness:false}
    ]
  }]; 
  var opciones = {
    zoom: 16,
    center: coordenadas,
    mapTypeId: google.maps.MapTypeId.ROADMAP
  }; 
  var mapa = new google.maps.Map(document.getElementById('mi-mapa'), opciones); 
  var estilo = new google.maps.StyledMapType(colores); mapa.mapTypes.set('mapa-bn', estilo); mapa.setMapTypeId('mapa-bn'); 
  var marcador = new google.maps.Marker({  
    position: coordenadas,
    map: mapa,
    title: 'Empresa',
    icon: 'images/logo.png'  
  });
}
google.maps.event.addDomListener(window, 'load', initialise);
</script>

the map appears and then disappears in less than a second.

    
asked by Cristina 17.02.2017 в 17:01
source

2 answers

0

I have deleted the credential that Google gave me and I have generated another api key with another email and it has been solved all keeping the initial scripts in the web page. Thanks

    
answered by 19.02.2017 / 13:36
source
0

You're calling initialise twice

One when the Load event of the window is triggered

google.maps.event.addDomListener(window, 'load', initialise);

And another one when the loading of the google scripts is completed and the callback is executed:

...&sensor=false&region=ES&callback=initialise

The error it gives you is because one of the two tries to execute initialise before it has been declined.

I would advise you to remove the listener from window.onLoad, and move the call to the google.maps script to the end of the document.

    
answered by 17.02.2017 в 17:56