Google Maps Key

0

I have a function that loads the API from Google Maps , but every time I try to change url , either to use my key, or even to add the library places to be able to use the search services I have problems.

The function I am using is this:

function loadScript() {
     var script = document.createElement('script');
     script.type = 'text/javascript';
     script.src = 'https://maps.googleapis.com/maps/api/js?v=3.exp&' + 'callback=initialize';
     document.body.appendChild(script);
 };
    
asked by anonymous 04.10.2015 / 21:06

2 answers

0

And it turned out that I was able to solve the problem, here is the solution if someone has something similar:

script.src = 'https://maps.googleapis.com/maps/api/js?v=3.exp&' + 'libraries=places&' + 'callback=initialize';
    
04.10.2015 / 21:30
0

In fact, creating a command to load a script is tricky and can cost you processing. In my scripts, I always call the Maps API, followed by the async and defer commands. These commands will ensure that the API is called in the background, that is, while you run your HTML, the API will be downloaded "together". An example call with async defer is this:

  

<script src="https://maps.googleapis.com/maps/api/js?key=YOUR_KEY&callback=init&libraries=places" async defer></script>

    
28.03.2017 / 18:55