0

I want my site to prompt for the user's ZIP code (it's US-only for now) and have Google return City/State/Lat/Long, which I store in my own table.

This is the query I'm using, for example (with the key at the end, of course):

http://maps.googleapis.com/maps/api/geocode/json?address=95112

that ZIP code works fine, as do lots of others. But some randomly fail. This is a pretty big ZIP code in San Francisco:

http://maps.googleapis.com/maps/api/geocode/json?address=94101

I know that prompting the user for their city/state would also work, but I'd like to avoid that requirement if possible and allow any user to just enter their ZIP.

What am I doing wrong?

  • 1
    The URL you provided for San Francisco works for me, is that an example of a "valid zip code that fails"? What is the error code you get when it "fails".? Please provide a [Minimal, Complete, Tested and Readable example](http://stackoverflow.com/help/mcve) that demonstrates your issue. – geocodezip May 30 '15 at 20:24
  • With the 94101 zip code, I get results in 4 countries. None of them USA. So this seems like a correct example of the issue. – matiasg May 30 '15 at 20:35
  • According to the [united states postal service](https://tools.usps.com/go/ZipLookupResultsAction!input.action?resultMode=2&companyName=&address1=&address2=&city=&state=Select&urbanCode=&postalCode=94101&zip=): **Sorry, 94101 is not a valid ZIP Code™. Please double-check it and try again.**, so your statement regarding "valid" zip codes is not correct. – geocodezip May 30 '15 at 20:40
  • see this question: http://stackoverflow.com/questions/4749706/lookup-city-and-state-by-zip-google-geocode-api You will see that a) google prohibits using their API unless you intend to use it with a map, and b) there are other alternatives. – matiasg May 30 '15 at 20:47

1 Answers1

0

According to the united states postal service: Sorry, 94101 is not a valid ZIP Code™. Please double-check it and try again.

geocodezip
  • 158,664
  • 13
  • 220
  • 245