ErrorPro / react-google-autocomplete

React components for google places API.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cannot read properties of undefined (reading 'places')

ladasfeed opened this issue · 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>

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

commented

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?

I'm facing the same issue :)

@L-Hendriks @ericdjavid hey guys, just pushed react-google-autocomplete@2.7.2 can u try if it works for you?

commented

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

Google maps places API must be loaded.

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?

Same here...

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