DEV Community

Discussion on: How to add Google Map script in a Vue project - without plugins

Collapse
 
prototypesean profile image
Dennis Kao

This is really helpful when I first trying to add google map to my current project,
but then I had to call map object from another component for street view, I can't pull it out :<

first I try to move

window.checkAndAttachMapScript = function (callback)

to root component, and have different callback function in different components, but got 'google is not define' error or

'You have included the Google Maps API multiple times on this page' error

can I bother you with a complete demo for a google map object using cross multiple components?

Collapse
 
tareqnewazshahriar profile image
Tareq Newaz Shahriar • Edited

Sorry, im late for 25 days ~facepalm~; haven't been checking dev.to for a while. Anyways.. did you solve it?

For now, I can point following things out-

first I try to move
window.checkAndAttachMapScript = function (callback)
to root component...

callback itself is a function, which is getting passed to another function. So not sure whether you made a typo here or you know exactly what you are doing!

but got 'google is not define' error

This is the reason I wrote this post. If you write new google.maps.StreetViewPanorama(...), you will get "google is not defined" error. You have to write: new window.google.maps.StreetViewPanorama(...).

'You have included the Google Maps API multiple times on this page' error

Probably every time you are calling checkAndAttachGoogleMap method, you are adding another <script> tag. So you need to review your code.

Some comments have been hidden by the post's author - find out more