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: 100%;
}
/* Optional: Makes the sample page fill the window. */
html, body {
height: 100%;
margin: 0;
padding: 0;
}
JavaScript
function stuff() {
console.log('Creating map div');
const m = document.createElement('div');
m.id = 'map';
m.style.display = 'none';
document.body.appendChild(m);
}
function initMap() {
const myLatLng = {lat: -34.397, lng: 150.644};
const m = document.getElementById('map');
if (m == null) {
console.log('Cannot find the "map" div.');
setTimeout(initMap, 10);
return;
}
console.log('creating map');
const map = new google.maps.Map(m, {
center: myLatLng,
zoom: 8
});
const marker = new google.maps.Marker({
position: myLatLng,
map: map,
title: 'Hello World!'
});
console.log('show map');
m.style.display = 'block';
}
setTimeout(() => {
stuff();
},25);