3

I'm interacting with two APIs, which return addresses that are formatted quite differently. One returns an address like "6 Avenue" and another returns "6 Ave."

I explored using the Normalic gem, but for some reason many of my addresses are returned malformed or blank: "6 Avenue" gets returned as "Ave.".

I also tried GeoCoder, but each API such as Google and Yahoo have set quotas. After a few hours of testing my app in development, these quotas expire. This obviously won't do in production.

It would be great if there was a library that let me do something like evaluate "6 Ave." == "6 Avenue".

Charles
  • 50,943
  • 13
  • 104
  • 142
Eric R.
  • 933
  • 1
  • 9
  • 19

2 Answers2

4

For US addresses, the USPS offers an address api. My understanding is that there is no charge, but your purpose needs to be for use with an e commerce website to validate addesses as they're entered.

For cleaning databases, the USPS often sends you to one of their (expensive) service providers for mailers.

Larry K
  • 47,808
  • 15
  • 87
  • 140
1

The Ruby StreetAddress gem should take care of this for you: https://rubygems.org/gems/StreetAddress

Here's some example usage for your case:

pry(main)> StreetAddress::US.parse("42 6 Ave., Washington, DC")
=> 42 6 Ave, Washington, DC
pry(main)> StreetAddress::US.parse("42 6 Avenue, Washington, DC")
=> 42 6 Ave, Washington, DC

So if you run both of your API addresses through the parse method, it should standardize both for you, and free up your life for more reflection, biking, and pizza consumption.

Dave Guarino
  • 509
  • 5
  • 14
  • 4
    Just a word of caution for those looking for a parser gem: from what I can tell, you won't find a 100% solution nor even 80% solution unless you go to the online APIs such as the USPS one or MelissaData (neither of which I've tried out). StreetAddress, for example, doesn't handle unit / apartment / suite numbers great, and breaks altogether if a C/O, Attn: or PO box are provided. We've settled on Normalic because it's more tolerant of malformed inputs, but still not super happy. – Topher Hunt Aug 27 '14 at 23:44
  • I agree with Topher about a parser gem not being very reliable. I am a software developer for SmartyStreets, which provides an address validation and standardization API like MelissaData does, and I can tell you getting reliable standardization is a tougher problem than it appears to be. – Neo Aug 01 '18 at 17:47