Last active
March 28, 2020 08:45
-
-
Save kikmedia/962d899946fb68e835cde2f6aed44eab to your computer and use it in GitHub Desktop.
Load Google Map only with consent
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
function initializeGoogleMap(id, address) { | |
var el = document.createElement('iframe'); | |
// put your settings here | |
el.width = 600; | |
el.height = 450; | |
el.frameborder = 0; | |
// put your query and your key here | |
el.src = 'https://www.google.com/maps/embed/v1/place?q=<your-query>&zoom=16&key=<your-api-key>'; | |
el.allowfullscreen = true; | |
document.getElementById('map' + id).appendChild(el); | |
} | |
// you will need a button with an ID #load-map on your page | |
document.querySelector('a[href="#load-map"]').addEventListener('click', function(e) { | |
// refer to proper class | |
initializeGoogleMap('346'); | |
document.getElementById('map346').style.display = 'block'; | |
e.preventDefault ? e.preventDefault() : e.returnValue = false; | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment