Solving street_number Bug in Google Address Autocomplete

Image for post
Image for post

We recently implemented Google Autocomplete for Addresses on our checkout page to simplify the process of entering a shipping address. Autocomplete is a fantastic service that makes address entry faster and error free … well, almost error free. While address typos are less frequent, addresses are failing our validation process because street number is missing.

The missing street number is a result of a known bug in Address Autocomplete where the drop-down list shows the correct address, but the PlaceResult object returned via JavaScript excludes the street_number field. Sadly, the bug was reported and confirmed by Google more than two years ago and still no progress towards a solution.

Fortunately, we won’t let a little bug stop us from providing a great feature! We developed a workaround (admittedly a hack) that grabs the street address (including street number) from the autocomplete field (lines 40–50):

Basically, we grab the full text of the autocomplete result and consider everything up to the first comma the street address.

The script may take some massaging for your specific scenario and form, but if you are only after the full street address, using the autocompleted input may be a good workaround. To extract the street_number from the input value would take a little RegEx and understanding of country-specific address formatting.

Don’t forget to head over to the bug report and add your vote. I’d much rather see this post become irrelevant and have a proper fix!

Enjoy! Feedback welcome.

Sharing thoughts on money, business, tech, faith, and life. I hope you learn from my mistakes!

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store