118
rated 0 times
[
123]
[
5]
/ answers: 1 / hits: 19528
/ 9 Years ago, mon, june 22, 2015, 12:00:00
I am trying to initialize the map load on a simple button click but with no luck. Also no errors being thrown in the javascript console.
If I change it to google.maps.event.addDomListener(window, 'load', initialize);
it works fine.
var showMap = $('#show-map');
function initialize() {
var mapOptions = {
center: { lat: 0, lng: 0 },
zoom: 8
};
var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
}
google.maps.event.addDomListener(showMap, 'click', initialize);
#map-canvas {
height: 30em;
width: 30em;
}
<script src=https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js></script>
<script src=https://maps.googleapis.com/maps/api/js?key=AIzaSyCgxY6DqJ4TxnRfKjlZR8SfLSQRtOSTxEU></script>
<button id=show-map>Show Map</button>
<div id=map-canvas></div>
More From » jquery