javascript - Google Maps JS: Uncaught TypeError: Cannot call method 'addDomListener' of undefined -
i'm getting "cannot call method 'adddomlistener' of undefined" error google.maps.event.adddomlistener(window, 'load', initialize);
code line, event
'undefined'. code below copied example on developer.google.com.
$(function () { var officemap = $("#map-canvas"); if (officemap.length > 0) { var map; function initialize() { var mapoptions = { center: new google.maps.latlng(-34.397, 150.644), zoom: 8 }; map = new google.maps.map(document.getelementbyid("map-canvas"), mapoptions); } google.maps.event.adddomlistener(window, 'load', initialize); } });
the google maps script (with api key) loaded before @ end of document body (using modernizr), looking this: "https://maps.googleapis.com/maps/api/js?key=myapikey&sensor=false" (i switch "myapikey" generate key ofc :))
does error indicate google maps script didn't load first? or api-key invalid? or else?
the google code sample correct, not going run in website given there ajax script loading involve. , yes right google script not loaded @ point when call function.
take @ source of google script, not full javascript sdk, proxy/starter file. remember not last time when sample code works without problem.
<script src="https://maps.googleapis.com/maps/api/js?sensor=false&callback=initialize"></script> <script> function initialize() { var officemap = $("#map-canvas"); if (officemap.length > 0) { var map; var mapoptions = { center: new google.maps.latlng(-34.397, 150.644), zoom: 8 }; map = new google.maps.map(document.getelementbyid("map-canvas"), mapoptions); } } </script>
Comments
Post a Comment