简体   繁体   English

Google地图的addListener

[英]addListener for Google Maps

I would like to print a google map, after the map is fully loaded. 地图完全加载后,我想打印一张Google地图。

[..] [..]

<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();">

But the addListener fires the information when the map is started and not fully loaded? 但是,当地图启动且未完全加载时,addListener会触发信息吗?

Try using a setTimeout function to delay the print call. 尝试使用setTimeout函数来延迟打印调用。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM