ErrorPro / react-google-autocomplete

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

How to verify if the input matches the selected address? #220

Open WillSmithTE opened 11 months ago

WillSmithTE commented 11 months ago

How do I get the actual text that was suggested to the user? The text that becomes the input's value on select?

E.g. search for 50 Abbotts Road, Dandenong South VIC, Australia

That comes up as a suggestion.

The user selects it, but then changes Abbotts to Abbots.

I thought the formatted_address would be 50 Abbotts Road, Dandenong South VIC, Australia, and I could compare this to the input value to check if they changed it. But it's not. The formatted_address is 50 Abbotts Rd, Dandenong South VIC 3175, Australia.

How do I validate this? How do I get the 50 Abbotts Road, Dandenong South VIC, Australia?

This seems to be a similar issue, but doesn't have an answer I could use with this library. https://stackoverflow.com/questions/18454677/google-maps-api-how-do-you-ensure-that-the-google-maps-autocomplete-text-is-an

insaurabh commented 10 months ago

How do I get the actual text that was suggested to the user? The text that becomes the input's value on select?

E.g. search for 50 Abbotts Road, Dandenong South VIC, Australia

That comes up as a suggestion.

The user selects it, but then changes Abbotts to Abbots.

I thought the formatted_address would be 50 Abbotts Road, Dandenong South VIC, Australia, and I could compare this to the input value to check if they changed it. But it's not. The formatted_address is 50 Abbotts Rd, Dandenong South VIC 3175, Australia.

How do I validate this? How do I get the 50 Abbotts Road, Dandenong South VIC, Australia?

This seems to be a similar issue, but doesn't have an answer I could use with this library. https://stackoverflow.com/questions/18454677/google-maps-api-how-do-you-ensure-that-the-google-maps-autocomplete-text-is-an

You can use ref to get the value from INPUT field, then compare that data with formatted_address.

WillSmithTE commented 9 months ago

@insaurabh thanks, but that's the issue. The formatted address is different to the input field's value.

e.g.

inputValue: '37 Bessemer Street, Kings Park NSW, Australia' formattted: '37 Bessemer St, Kings Park NSW 2148, Australia'

They are slightly different.

insaurabh commented 9 months ago

@WillSmithTE

You can update the

options: { types: ["(regions)"], <--- to address or some valid type, check google doc. },

and then on selection of address, create your own dropdown.