This offline zip code geocoder stores a list of 28,000 US zip codes with their geocoded locations, searches them using JavaScript, and is accessible via URL parameters in HTML.
Admittedly, using zip code offline is less useful than city and state, because when you are away from home, you are probably aware of a nearby city, but you probably don't know the zip code. But this may be useful for a single-page app that needs to determine a zip code's location without going online.
Because we're trying to locate zip codes and not specific addresses, it's not important to have meters of precision, so the data entries have only three decimal places, which translates to about 0.6 miles or 1 kilometer.
For city and state, you're better off using this offline city and state geocoder.
The database is contained in this HTML file that is actually a big JavaScript file. It is intended that you bring up the HTML file with URL parameters that indicate the city and state you want to query. For example ...
... shows latitude & longitude for zip code 95030 (Los Gatos, CA).
Further, it is intended that the URL parameters include a return
parameter that indicates the calling page. When invoked in this way, the geo.html
page will invoke the calling page with all its original URL parameters, plus
longitude and latitude parameters. An example would be ...
geozip.html?zipcode=95030&return=zipcode.html
... which immediately redirects back to this page with the extra URL parameters appended.
You can add logic to your page to detect the additional URL parameters and do something useful with them. In this case, the page prints the coordinates and displays a Google Map of the queried zip code. (Of course, if you're truly offline, the Google map won't appear, but the coordinates should still be reported in text.)
» The latitude is
» The longitude is