react-google-autocomplete icon indicating copy to clipboard operation
react-google-autocomplete copied to clipboard

Cannot read properties of undefined (reading 'places')

Open ladasfeed opened this issue 2 years ago • 7 comments

Sometimes i get an error here.

https://github.com/ErrorPro/react-google-autocomplete/blob/master/src/usePlacesWidget.js

Cannot read properties of undefined (reading 'places')

if (!google.maps.places) return console.error("Google maps places API must be loaded.");

Notice that you can pass a callback to a script url now. It would be easier to handle everything.

<script async
    src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&libraries=places&callback=initMap"> // initMap is a custom window.initMap function
</script>

ladasfeed avatar Aug 17 '22 14:08 ladasfeed

the issue is that if your code is inside a bundle then it's hard to get it exposed to the global scope. I'll add another check fo .maps.places. If you have time u can create a PR with the fix and I'll merge it

ErrorPro avatar Aug 18 '22 10:08 ErrorPro

I'm also encountering this issue, but I'm not sure what the problem is. Happy to create a PR, but what kind of check are you talking about?

doc-l avatar Oct 10 '22 09:10 doc-l

I'm facing the same issue :)

ericdjavid avatar Jan 17 '23 22:01 ericdjavid

@l-hendriks @ericdjavid hey guys, just pushed [email protected] can u try if it works for you?

ErrorPro avatar Jan 19 '23 09:01 ErrorPro

Upgraded to "react-google-autocomplete": "^2.7.2", but still encountering the same issues:

Google maps places API must be loaded.

ewhanhan avatar Jan 24 '23 01:01 ewhanhan

the issue is that if your code is inside a bundle then it's hard to get it exposed to the global scope. I'll add another check fo .maps.places. If you have time u can create a PR with the fix and I'll merge it

Same here. undefined is not an object (evaluating 'new google.maps.places')

iOS: 17.0 react-google-autocomplete: "2.7.3"

Is there any solution for this issue? If the PR cannot be merged, can we fix it using patch-package?

ArianHamdi avatar Feb 16 '24 18:02 ArianHamdi

Same here...

but it seems that this issue only happens when the page gets fully reloaded...

marik22312 avatar Jun 13 '24 10:06 marik22312