alexreisner/geocoder

Zip code / postal code search only sometimes returns US-based zip codes

jc-adamjubert opened this issue · 2 comments

Expected behavior

Entering a zip code will return the coordinates of that US-based zip code.

Actual behavior

Entering a zip code will only sometimes return the coordinates of a US-based zip code.

Steps to reproduce

// returns the New York, NY, USA
> Geocoder.search("10003").first.coordinates  
=>  [40.73153057641129, -73.98862253649193]  

// returns Taitung City, Taiwan
> Geocoder.search("10014").first.coordinates  
=>  [22.7553667, 121.1506] 

I was able to fix this by utilizing params: { countrycodes: "us"} ("10014 USA" also works), however it wasn't immediately obvious that this was an issue because it only happens with some US-based zip codes. I might recommend throwing a caveat in the README that zip code searches should include specific country-only searches.

Environment info

  • Geocoder version: 1.3
  • Rails version: Rails 6.1.4.1
  • Database (if applicable): PostgreSQL
  • Lookup (if applicable):

Hmm, yes, I've seen inconsistent behavior like this from a few of the APIs. Which one were you using? I'm hesitant to mention this explicitly in the README because every API has quirks that manifest in different ways (and which are constantly changing as the APIs evolve) and it seems impossible to give warnings for every use case.

Great point - I'm using the default API. I'll try switching up APIs to see if that fixes it.