gpt4 book ai didi

google-maps - 如果异步加载 gmap 时未指定回调,则不会加载其他必要的谷歌地图脚本

转载 作者:行者123 更新时间:2023-12-02 19:37:51 25 4
gpt4 key购买 nike

这是否记录在某处,我需要指定回调才能定义 google.maps 模块?或者这是一个错误。

以下代码不会加载谷歌地图模块:

<!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>

编辑——回复答案

To do so, you can inject your own tag in response to a window.onload event or a function call, but you need to additionally instruct the Maps JavaScript API bootstrap to delay execution of your application code until the Maps JavaScript API code is fully loaded. You may do so using the callback parameter, which takes as an argument the function to execute upon completing loading the API.

这如何意味着没有回调将不会加载任何 api?它说当代码完全加载时,您可以使用回调参数来执行函数,但它并没有说如果没有回调参数,代码将永远不会加载。

最佳答案

关于google-maps - 如果异步加载 gmap 时未指定回调,则不会加载其他必要的谷歌地图脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9355572/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com