Offline Geocoder

JavaScript App

Purpose

This offline geocoder is a database of over 14,000 cities across the United States with their geocoded locations. These represent all cities with population greater than 1000. The database searches them using JavaScript, and is accessible via URL parameters in HTML.

Why Offline

Even if you are offline, you can look up the city at your current location, or any city, and get its longitude and latitude coordinates. Note that because we're trying to locate cities 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.

This can be useful if you are trying to look up something from your motel room or your car when you don't have an internet connection. This project comes with some static databases of things like book stores, national parks, and gluten free restaurants that can be looked up even when there is no internet connection.

This offilne zip code geocoder is probably less useful but it's still fun.

Accessing the Database

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 ...

geo.html?city=Cupertino&state=CA

... will show the latitude and longitude for Cupertino, California.

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 ...

geo.html?city=Cupertino&state=CA &return=offline.html

... which immediately redirects back to this page with the extra URL parameters appended.

Try It

Using the Results

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 city. (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

Copyright © 2007–2014 Mark Brautigam