Is there any package available on npm for google maps? Or am I really supposed to paste this
<script src="https://maps.googleapis.com/maps/api/jskey=YOUR_API_KEY">
</script>
to my index.html and download this js file on every refresh?
This is super annoying, because sometimes I get ReferenceError: google is not defined
.
The official google maps package (@google/maps) is for node only. In a browser environment, you need to use an unofficial package or include the official script on your site.
To the ReferenceError problem, make sure the script tag for google maps is above the script tag for your code so that it loads first. If it isn't, your script may run before the google global variable is created.
One unofficial package is google-maps, which can be used in a browser.