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.
Answer from pfg on Stack Overflow
» npm install google-maps
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.
Or am I really supposed to paste this to my index.html and download this js file on every refresh?
Yes. This is the only way to do so. There are some packages to dynamically do this for you, but the behavior is the same.
To reiterate, there is no official package for loading the Google Maps JavaScript for the web environment on NPM. The @google/maps referenced by others is for node only.
google is not defined errors can be avoided by using the callback query parameter when loading the google maps script.
Update - 2020/01/17
I wrote @googlemaps/js-api-loader to help load the script dynamically and support promises.
import { Loader } from '@googlemaps/js-api-loader';
const loader = new Loader({
apiKey: "",
version: "weekly",
libraries: []
});
loader
.load()
.then(() => {
new google.maps.Map(div, mapOptions);
})
.catch(e => {
// do something
});
What is the best npm package for the google map api?
migrate agm/core to angular/google-maps
agm/core was last published 4 years ago. It no longer seems to be maintained. I would switch to angular/google-maps.
More on reddit.comGoogle Maps and ThreeJS - npm i @googlemaps/three
Published an initial version of https://www.npmjs.com/package/@googlemaps/three for combining ThreeJS and Google Maps. Check it out and let me know what you think.
More on reddit.comBest React NPM package for Google Places Autocomplete?
» npm install @types/google.maps
» npm install @react-google-maps/api
» npm install @google/maps
» npm install @angular/google-maps
» npm install @googlemaps/google-maps-services-js
» npm install googlemaps
Hey,
I have been recently working with "google-map-react "(https://www.npmjs.com/package//google-map-react), which I chose because it seemed to be the most popular google map react package. The way you setup markers and stuff like that is great, and pretty simple to understand. You can also directly load geojson files, which is nice. However more I work with it, more I feel like it is not very "reacty". It is probably just me not fully understanding how the package works yet, but I cannot understand how to draw polylines in a reacty way (as there is no polyline component).
Would you say that this is the best package to use to create a simple app that shows routes, with the ability of filter said routes?
Or should I choose something else?
I am wondering if it is just worth keep working with it, or just use something else.
» npm install @capacitor/google-maps
» npm install @types/googlemaps
» npm install google-maps-api