我想在地图完全加载后打印谷歌地图。
[..]
<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会触发信息吗?
答案 0 :(得分:-1)
尝试使用setTimeout函数延迟打印调用。
directionsService.route(request, function(result, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(result);
setTimeout(function() { alert('Funktion wird aufgerufen!'); }, 2000);
}
});