0

I load google maps api using the async tag provided (below). I want to load a javascript file (that contains some class definitions that extend google maps api). How can I make sure the javascript is loaded after the Google Maps API JS is loaded?

<script async defer
        src="https://maps.googleapis.com/maps/api/js?key=***************&callback=initMap">
</script>

I tried putting this in the initMap function to load the javascript but it still loaded the js too quickly and consequently the "google is not defined" errors still occurred

 $.getScript("/assets/js/ContextMenu.js");
7
  • Just change your &callback=initMap? Commented Mar 6, 2019 at 11:28
  • I don't understand what you mean. my initMap() initalises the map on the page. Commented Mar 6, 2019 at 11:30
  • I'd think you could either change the initMap function to initiate your other plugin as well, or set the callback to something else that initiates your plugin and then calls initMap Commented Mar 6, 2019 at 11:31
  • That's what I'm asking, how do I load the other Javascript file after google maps has loaded. I can't find any way to control the order of loading Commented Mar 6, 2019 at 11:32
  • @CertainPerformance Please remove the duplicate, it doesn't do the same thing, I want to load in a file, not execute an arbitrary Javascript command. Commented Mar 6, 2019 at 11:44

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.