I have a script section in my html file where I create a new instance of my gmap
object. Outside of the function initMap()
the variable gMap
is undefined although I declared it outside of the function.
var gMap;
function initMap() {
gMap = new gmap({
//some Properties
});
console.log(gMap); //gMap is defined
}
console.log(gMap); //gMap is undefined
The function is called like this:
<script async defer
src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&callback=initMap">
</script>
I also tried calling it through $(document).ready
instead of google API callback but it changed nothing.