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

How to verify if the input matches the selected address?

Open WillSmithTE opened this issue 2 years ago • 3 comments

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

WillSmithTE avatar Aug 02 '23 15:08 WillSmithTE

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.

insaurabh avatar Sep 13 '23 09:09 insaurabh

@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.

WillSmithTE avatar Oct 02 '23 19:10 WillSmithTE

@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.

insaurabh avatar Oct 08 '23 03:10 insaurabh