Simple Map

by Wolf

HTML

<!-- Replace the value of the key parameter with your own API key. -->
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCkUOdZ5y7hMm0yrcCQoCvLwzdM6M8s5qk&callback=initMap" async defer></script>

CSS

/* Always set the map height explicitly to define the size of the div
 * element that contains the map. */
.map {
  height: 425px;
}
/* Optional: Makes the sample page fill the window. */
html, body {
  height: 100%;
  margin: 0;
  padding: 0;
}

JavaScript

var map;
function initMap() {
  let mapDiv = document.createElement('div');
  mapDiv.className = 'map';
  map = new google.maps.Map(mapDiv, {
    center: {lat: -34.397, lng: 150.644},
    zoom: 8
  });
  google.maps.event.addListenerOnce(map, 'idle', () => {
  	console.log('attaching map...');
  	document.getElementsByTagName('body')[0].appendChild(mapDiv);
  });
}