此代码google.maps.event.addDomListener(window, 'load', initialize);
仅在我重新加载/刷新页面时运行。但是,我希望它只需单击按钮或在浏览器中打开页面时显示?我该怎么做
<script>
function initialize() {
var chicago = new google.maps.LatLng(41.875696,-87.624207);
var mapOptions = {
zoom: 11,
center: chicago
}
var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
var ctaLayer = new google.maps.KmlLayer({
url: 'http://gmaps-samples.googlecode.com/svn/trunk/ggeoxml/cta.kml'
});
ctaLayer.setMap(map);
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
答案 0 :(得分:3)
尝试将事件侦听器附加到其他元素:
google.maps.event.addDomListener(document.getElementById('myButton'), 'click', initialize);