/**
* @license
* Copyright 2019 Google LLC. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/
/*
* 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
// Set up a promise that resolves when initMap is called.
let _gmapsLoaded = new Promise(function(resolve, reject) {
window.initMap = resolve;
});
// 10s timeout
let _gmapsTimeout = new Promise(function(resolve, reject) {
// Optional...
setTimeout(function() {
reject(new Error('gMaps load took too long!'));
}, 10000);
});
// A promise that fullfills when initMap is called, or fails after 10s
let _gmapsInitialized = Promise.race([_gmapsLoaded, _gmapsTimeout]);
// Do things with google.maps...
function renderMap() {
new google.maps.Map(document.getElementById("map"), {
mapId: "8e0a97af9386fef",
center: {
lat: 48.85,
lng: 2.35
},
zoom: 12,
});
}
// Call renderMap when _gmapsInitialized fulfills, or throw an error.
(async function callFnAfterPromise(fn, p) {
await p;
fn.call();
}(renderMap, _gmapsInitialized));
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.