Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to install google maps through npm?

Tags:

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.

like image 563
feerlay Avatar asked Oct 23 '17 18:10

feerlay


People also ask

Is Google Maps API free?

The API is available for developers that have a free Google Maps API key. Usage of the API is not strictly free, but they do offer $200 of free monthly usage for most users. The pricing scales to fit your particular needs and you are only charged for your API usage.


1 Answers

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.

like image 126
pfg Avatar answered Sep 20 '22 17:09

pfg