ErrorPro / react-google-autocomplete

React components for google places API.
MIT License
462 stars 114 forks source link

onPlaceSelected not being executed #229

Open loixiyo opened 6 months ago

loixiyo commented 6 months ago

Hi,

I have copy-pasted the code and the autocomplete service seems to be working. But the funcion onPlaceSelected is not being executed. Could you please help me? This is the code I'm using:

<Autocomplete style={{ width: "90%" }} options = {{ types: ['point_of_interest'], fields: ["name", "formatted_address", "geometry", "place_id"], componentRestrictions: { country: "es" } }} onPlaceSelected={(place) => { console.log(place); }} />

Thanks!

meghana-ravikumar commented 5 months ago

Hi @loixiyo,

I faced the same issue, you can try adding apiKey={} property to the component. Something like this :

<Autocomplete apiKey={API_KEY} style={{ width: "90%" }} options = {{ types: ['point_of_interest'], fields: ["name", "formatted_address", "geometry", "place_id"], componentRestrictions: { country: "es" } }} onPlaceSelected={(place) => { console.log(place); }} />

This fixed my issue.