Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot instantiate google object ( google is undefined ) #485

Closed
xshadowlegendx opened this issue Apr 30, 2017 · 7 comments
Closed

Cannot instantiate google object ( google is undefined ) #485

xshadowlegendx opened this issue Apr 30, 2017 · 7 comments

Comments

@xshadowlegendx
Copy link

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.

@Rupeshn73
Copy link

Rupeshn73 commented May 10, 2017

@xshadowlegendx I have faced this same issue before. So please refer to my question on same topic (ex) Stackoverflow react-google-map

@MRustem
Copy link

MRustem commented May 15, 2017

Connect the api tag before the bundle.js

@sebasgarcep
Copy link

sebasgarcep commented 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.

@mpowell90
Copy link

mpowell90 commented Jun 12, 2017

This helped resolve my 'google is undefined' issue.
https://stackoverflow.com/questions/43714895/google-is-not-defined-in-react-app-using-create-react-app

My build is React.js with Next.js.

@oshalygin
Copy link
Collaborator

@sebasgarcep I'll put a PR together and add it to the README, because this comes up way too often. Since you haven't sent a PR yet, I'll just open it up now.

oshalygin added a commit to oshalygin/react-google-maps that referenced this issue Jul 24, 2017
- This commit provides a bit of color on how
  to get started with the library.
- The steps include walking through the Google
  Maps API tutorial on obtaining an API key, followed
  by including the library in the application either
  statically as a script reference in index.html
  or through the component as googleMapURL.

Addresses tomchentw#485
oshalygin added a commit to oshalygin/react-google-maps that referenced this issue Jul 24, 2017
- This commit provides a bit of color on how
  to get started with the library.
- The steps include walking through the Google
  Maps API tutorial on obtaining an API key, followed
  by including the library in the application either
  statically as a script reference in index.html
  or through the component as googleMapURL.

Addresses tomchentw#485
oshalygin added a commit that referenced this issue Jul 25, 2017
- This commit provides a bit of color on how
  to get started with the library.
- The steps include walking through the Google
  Maps API tutorial on obtaining an API key, followed
  by including the library in the application either
  statically as a script reference in index.html
  or through the component as googleMapURL.

Addresses #485
@tomchentw
Copy link
Owner

A possible solution is using withScriptjs
https://tomchentw.github.io/react-google-maps/#directionsrenderer

@GrolaElmahdi
Copy link

You can try this after imports :

const google = window.google

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants