question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot instantiate google object ( google is undefined )

See original GitHub issue

I am using MeteorJS ( 1.4.4 ) + ReactJS, currently i can get the map, markers, working properly. I am using ’ withScriptjs.js ’ async method to render the map, because i tried without the async and it does not work. Here is my problem, i want to use the DirectionsRenderer to draw direction, which is must needed for my traffic jam project, and following the example, I cannot get it works because of google is undefined when the code runs until const DirectionsService = new google.maps.DirectionsService(); throws the error inside componentDidMount(). Because I am still on testing the package, so there is no complex code, and my code was just exactly the same as the example code ( directions ). Thanks you very much for helping. PS: Awesome package with almost google api completed.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
sebasgarcepcommented, May 17, 2017

Solved it by adding:

<script src="https://maps.googleapis.com/maps/api/js"></script>

to the head of my index.html, as suggested in the demo project’s source code.

@tomchentw This should be documented, willing to send in a pull request.

1reaction
GrolaElmahdicommented, May 19, 2018

You can try this after imports :

const google = window.google

Read more comments on GitHub >

github_iconTop Results From Across the Web

window.google is undefined in react? - javascript
Hey I came across a similar issue trying to instantiate a new window.google.maps.Map and found this solution helped me.
Read more >
Directions Service | Maps JavaScript API
This object communicates with the Google Maps API Directions Service which receives direction requests and returns an efficient path. Travel time is the...
Read more >
Uncaught ReferenceError: google is not defined (Example)
Hello, I am working on a website project and not being able to find a solution to the below mentioned problem. The chrome...
Read more >
Google Maps API Common Errors & Solutions
Include the Maps Javascript library before creating google maps map object. ... Scenario #2: Adding a callback parameter with a initMap() function ......
Read more >
4 gotchas when setting up Google Maps API with Next.js ...
The object called google is used without being defined. ESLint doesn't like it. And it is a compile error. So you cannot tell...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found