Question

Okay I'm not really sure how to explain this clearly so the title might have been slightly confusing. I have some code for using the google maps api from w3 schools (http://www.w3schools.com/googleAPI/google_maps_basic.asp) which is shown as going in the head tag of the html file. But I am also trying to use Meteor.js for another part of the app and it separates the javascript code into another .js file. So basically I am wondering how/where to put the javascript code from the head tag into the meteor .js files. I tried to put it directly in but I think it needs the other script tag to go with it because it has some variables that weren't defined if I moved it. So how can I move the javascript code and make sure that the variables are still defined? Should I move the script src tag with it somehow?

<script src="https://maps.googleapis.com/maps/api/js?key=myKey"> </script>
<script>
    //javascript code I want to move is here
</script>

I've also read something about dynamically loading the javascript with jQuery or something but I'm not sure I understand how that would work?

Here is the github repo of the code but I don't think you'll need it: https://github.com/2016rshah/meteor/tree/master/FlightNews

Sorry for asking such a silly question I am new to web-dev and I've never really faced problems like this with Java or Python because you can just import wherever you need to. Thanks for any suggestions!

Was it helpful?

Solution

It is not a silly question. Others have had the same problem, too. This question has two good answers that will solve your problem. In the comments you'll also find a blog post about the issue.

However, you may also want to consider using a Meteor package that was developed to ease integration of Google Maps into Meteor. One example is googlemaps but there are also others. There's also an example showing you how to use the package.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top