If the callback is not specified during asynchronous loading of gmaps, other necessary google map scripts are not loaded

Is it documented somewhere that I need to specify a callback to define the google.maps module? Or is it a mistake.

The following code does not load the google maps module:

<!DOCTYPE html> <html> <head> <title> Google Maps JavaScript API v3 Example: Asynchronous Map Simple </title> <meta name="viewport" content="initial-scale=1.0, user-scalable=no"> <meta charset="UTF-8"> <style type="text/css"> html { height: 100% } body { height: 100%; margin: 0; padding: 0 } #map_canvas { height: 100% } </style> <script type="text/javascript"> function initialize() { var myOptions = { zoom: 8, center: new google.maps.LatLng(-34.397, 150.644), mapTypeId: google.maps.MapTypeId.ROADMAP }; var map = new google.maps.Map(document.getElementById('map_canvas'), myOptions); } function loadScript() { var script = document.createElement('script'); script.type = 'text/javascript'; script.src = 'http://maps.googleapis.com/maps/api/js?v=3.6&key=myKey&sensor=false' //adding 'callback=something' gets the maps module to load document.body.appendChild(script); } window.onload = loadScript; </script> </head> <body> <div id="map_canvas"></div> </body> </html> 

Edit - Reply to Reply

To do this, you can enter your own tag in response to a window.onload event or function call, but you need to further instruct the JavaScript JavaScript API boot file to delay the execution of the application code until the JavaScript JavaScript API code is fully loaded. You can do this using the callback parameter, which takes as an argument the function that executes after the API loading completes.

How is this meant that the lack of a callback will not load any of the api? It says that you can use the callback parameter to execute the function if the code is fully loaded, but it does not say that the code will never load without the callback parameter.

+8
google-maps google-maps-api-3
source share
1 answer
0
source share

All Articles