gpt4 book ai didi

javascript - 为 Google map 添加监听器

转载 作者:行者123 更新时间:2023-11-28 10:59:37 24 4
gpt4 key购买 nike

我想在 map 完全加载后打印谷歌地图。

[..]

<link href="http://code.google.com/apis/maps/documentation/javascript/examples/standard.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="http://maps.google.de/maps/api/js?sensor=false">
</script>
<script type="text/javascript">

var directionsService = new google.maps.DirectionsService();
var map;
var gh;


function initialize() {
//alert("Starte Funktion");
directionsDisplay = new google.maps.DirectionsRenderer();
gh = new google.maps.LatLng(41.850033, -7.6500523);
var myOptions = {
zoom:15,
mapTypeId: google.maps.MapTypeId.ROADMAP,
center: gh
}
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
directionsDisplay.setMap(map);

}

function calcRoute() {
//alert("Starte calcRoute");
//alert("<?php echo $adresse; ?>");
var start = "Recklinghausen Akkoallee 45";
var end = "Recklinghausen <?php echo $adresse; ?>";
var request = {
origin:start,
destination:end,
travelMode: google.maps.DirectionsTravelMode.DRIVING,
avoidHighways: true,
};
directionsService.route(request, function(result, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(result);
}
});

google.maps.event.addListenerOnce(map,'idle', function(){
alert('Funktion wird aufgerufen!');
//window.print();
});
}
</script>

[..]

<body onload="initialize();calcRoute();">

但是本地图启动且未完全加载时,addListener 会触发信息?

最佳答案

尝试使用 setTimeout 函数来延迟打印调用。

directionsService.route(request, function(result, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(result);
setTimeout(function() { alert('Funktion wird aufgerufen!'); }, 2000);
}
});

关于javascript - 为 Google map 添加监听器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8314768/

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