1

Our app's postal-address entry UI is a two-line Address1/Address2 field like this (borrowing screenshot from Amazon.com).

enter image description here

But real users' data entry is always messy. Some users will ignore our directions and will sometimes put the street address in Address1 and sometimes put it in Address2. Other users will import lists of addresses from external sources (like an existing mailing list), which will also likely cause some cases where the street address is unpredictably in Address1 or Address2.

When it comes time to geocode the address, what's a good algorithm to maximize the chance of successful geocoding if we're not sure whether the street address is in Address1 or Address2? A naive approach could be to try Address1, and if it fails then try Address2. But I'm sure I'm not the first person to try geo-coding real-world messy data entry... how is this problem usually solved?

We're using the Google Maps Geocoding API, if it matters.

Justin Grant
  • 44,807
  • 15
  • 124
  • 208

1 Answers1

1

I believe Google recommends using the autocomplete widget.

Have a look at the best practices document:

https://developers.google.com/maps/documentation/geocoding/best-practices

It says

Respond, in real time, to user input (includes ambiguous, incomplete, poorly formatted, or misspelled addresses entered by a user)

Use the Places API Place Autocomplete service to obtain a place ID, then the Geocoding API to geocode the place ID into a latlng.

Apartment, suite, unit etc. typically is not present in Google database. So you can bind the autocomplete to the first input where the user selects address and you can get corresponding place ID, the rest of information the user can enter in the second field which is not relevant for Google Geocoding API.

There are several examples of place autocomplete in the official documentation.

https://developers.google.com/maps/documentation/javascript/examples/places-autocomplete

https://developers.google.com/maps/documentation/javascript/examples/places-autocomplete-addressform

https://developers.google.com/maps/documentation/javascript/examples/places-placeid-geocoder

I hope this helps!

Community
  • 1
  • 1
xomena
  • 31,125
  • 6
  • 88
  • 117