我正在尝试异步加载谷歌地图,它可以正常工作,但会加载两次地图。如果我删除“
box.onload = initialize;
”,则可以解决此问题,但是信息框不会显示...如何修复代码以仅加载一次地图并显示信息框?function loadScript() {
var map = document.createElement('script');
map.type = 'text/javascript';
map.src = 'https://maps.googleapis.com/maps/api/js?key=key_goes_here&sensor=false&callback=initialize';
document.body.appendChild(map);
map.onload = function() {
var box = document.createElement('script');
box.type = 'text/javascript';
box.src = 'https://google-maps-utility-library-v3.googlecode.com/svn/trunk/infobox/src/infobox_packed.js';
document.body.appendChild(box);
box.onload = initialize;
};
}
window.onload = loadScript;