-
Notifications
You must be signed in to change notification settings - Fork 935
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
google is not defined? #414
Comments
withGoogleMap.js? withGoogleMap is higher order component wrapper, should not be a file name. import {withGoogleMap, GoogleMap, Marker} from 'react-google-maps';
const GoogleMapHOC = withGoogleMap(
props => ( <GoogleMap> <Marker/> </GoogleMap>)
) |
You must run the google maps script in your index.html |
@seansinflipflops as @ZephD said, insert
in the top of you index.html file and you should be good to go. |
One of my users got this error today as well actually, even though I'm wrapping it correctly. Or at least it has been working for months (see below). Could there be a possible race condition/timeout case which could cause this? const AsyncGoogleMap = _.flowRight(
withScriptjs,
withGoogleMap,
)(props => (
<GoogleMap
ref={props.onMapLoad}
[...]
>
[...]
</GoogleMap>
));
class MyComponent extends React.Component {
<AsyncGoogleMap
googleMapURL="https://maps.googleapis.com/maps/api/js?v=3.25&libraries=geometry,drawing,places&key=<key goes here>"
[...]
/>
} |
@sho13 I'm not so sure. The whole idea with the |
Can you find out where in withScripts google is used but not defined? |
@ZephD On the exact same line as reported in this issue.
Which is:
|
I ran into the same issue due to me using eslint. In order to over come this issue I had to add at the top of my file: |
@davidpatters0n solution did the trick for me! |
eslint is an IDE warning/error. Should not have problems when running. |
The eslint issue is not the problem. you're likely not including the necessary google maps script. |
@ZephD whenever I insert <script src="https://maps.googleapis.com/maps/api/js?key=YOUR_KEY></script>I just get "unterminated string literal" and it messes with the rest of the code. Any ideas? I've tried to change "</script>" to "</script>" and also tried changing it to "</scr"+"ipt>" but neither worked. Thanks. |
<script src="https://maps.googleapis.com/maps/api/js?key=YOUR_KEY></script> Where are you trying to add this script? It should go into your Please refer to the updated README documentation: |
Missing " after YOUR_KEY |
@sho13 Were you able to solve it? I am facing the exact same issue. error log:
running react-google-maps@7.2.0 |
Wrap your component with withScriptjs() and it should only load if google is available. |
@ZephD " it should only load if google is available." how? I have followed the async example. Can you please give an example? |
See #414 (comment) |
I'm getting errors about missing props using the aforementioned technique. Code: import { withGoogleMap, GoogleMap, InfoWindow, Marker } from 'react-google-maps';
import withScriptjs from 'react-google-maps/lib/async/withScriptjs';
const Map = withScriptjs(withGoogleMap(props => (
<GoogleMap
defaultZoom={17}
center={props.center}
>
{ ... handling markers here, unrelated ... }
</GoogleMap>
))); I have the script reference in my index.html. Here is the error message: Running Edit: same on |
Where you use |
try adding |
Excellent! |
I am getting the error google is not defined for following code:
|
your |
does anyone was able to solve this? i'm getting Cannot read property 'maps' of undefined withGoogleMap. js line 149 I tried to change this line to var map = new window.google.maps.Map(node) |
ok I think I solved it. then on the map component just use it like this: const yourComponent = withGoogleMap(props => ( It solves the refresh google is not defined problem. app will no more crash on refresh |
You mean your error occurs here? Great you solved it, but the compose version should have done the same thing. |
With compose google was undefined on withGoogleMap.js file, because I didn't reference maps api on index head. Once I reference the maps api on the head it complained I called the maps api multipile times. and also was crahing every 2nd refresh. bad cycle. |
That's because you continued to use "withScriptjs". Either use the head script, or withScripjs. |
I don't know I did exactly like step 5 in the documentation and still google was undefined. sorry it was not defined |
what worked for me: |
It's still happening on every other page load http://ec2-18-196-246-145.eu-central-1.compute.amazonaws.com/ Something wrong with this library |
you need withScriptjs(withGoogleMap( ... )) |
@oshalygin is this issue ok to lock as it's been solved? |
Looks like the issue is resolved when adding withScriptjs(withGoogleMap( ... )) |
Make sure you run the script without "async defer" flag, otherwise it might not load in the correct order. |
If you already follow every comment in this page, you can try this solutions (IF you are using create-react-app) |
Our users have been receiving this error inconsistently in production. We use withScriptJs and withGoogleMap hoc, though for unknown reasons, following links will break the code here: https://github.com/tomchentw/react-google-maps/blob/master/src/withGoogleMap.jsx#L59 Any suggestion will be greatly appreciated! |
The withGoogleMap function doesn't prevent "google is not loaded" error. I proposed a solution to this in In my case, my system operates offline too and this crash is right. |
It solved the problem,Thank you |
Adding |
LoooooooL, I was trying to solve that issue for the last hour. Just make sure to |
Our app still has classes and I found the easiest way was to create a wrapper component that uses the useJsApiLoader hook. withGoogleMap.js
SomeComponent.js
|
Hey, I keep getting a reference error for google in the withGoogleMap at line 101.
Uncaught ReferenceError: google is not defined - withGoogleMap.js:101
Does anyone know how to remedy this error?
The text was updated successfully, but these errors were encountered: