2011-11-29 93 views
1

我想在地图完全加载后打印Google地图。Google地图的addListener

[..]

<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

这是我能做的最好的:Map对象理应触发一个'tilesloaded'事件](http://code.google.com/apis/maps/documentation/javascript/reference.html#Map ),但是当我将“addListenerOnce”更改为“tilesloaded”而不是“idle”时,在图像出现之前,我仍然收到警告框。祝你好运。 – sdleihssirhc

回答

-1

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

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