when open page javascript runs before button clicked. runs when click button. don't want run until click button.
code:
function initmap() { var map = new google.maps.map(document.getelementbyid('map'), { center: {lat: 45.973, lng: -68.81}, zoom: 10 }); } html, body { height: 100%; margin: 0; padding: 0; } #map { height: 50%; } <div id="map"></div> <button id="showlocation" onclick="initmap()">show location</button> <script src="https://maps.googleapis.com/maps/api/js?key=aizasydtue6nav7fwxooeswnedq3yct9y2wr8lg&callback=initmap" async defer></script> thanks in advance!
you passing initmap callback 'api/js'. means when script loads run callback method, i.e. execute initmap.
try removing &callback=initmap url.
Comments
Post a Comment