Skip to content

The BIG Reason

Music, opinions, and portfolio of Mark Eagleton, musician and web developer in Northern CA.

The Science of Zip Code Searching

A recent project had me describing the particulars of zip code searching—or more accurately—the accuracy of the results of zip code searching. The client wanted a location search feature in the side bar of their site where the visitor enters a zip code, and is presented with a list of the nearest locations to them, like the one in the sidebar of Walmart.com.

A recent project had me describing the particulars of zip code searching—or more accurately—the accuracy of the results of zip code searching. The client wanted a location search feature in the side bar of their site where the visitor enters a zip code, and is presented with a list of the nearest locations to them, like the one in the sidebar of Walmart.com.

The benefit of such a feature is that it's an extremely fast way to list a few of the nearest store locations for visitors. It is not, however, an exact science. But that is generally not an issue for the visitor, as most people are quite familiar with the areas they are searching.

It was an issue for the client, however. They wanted to list the search results in order from nearest to furthest, which is perfectly reasonable, but not 100% accurate. The accuracy issue was compounded by the fact that they wanted the mileage listed among the search results. This makes the discrepancies much more obvious. Allow me to illustrate:

If you are searching for a location nearest to the zip code 95695, and the nearest location is actually in 95695, what is the mileage? Zero?

The actual search logic I built into this site uses the Google Maps API to return distance results based on its latitude and longitude entries. I have the exact latitude and longitude entries of the client's store locations stored in the database, so there will be an actual mileage number calculated from that location and whatever Google's default latitude and longitude entries are for that zip code. This is hardly an accurate distance of measure.

Let's say that my address is 1100 Main Street, Woodland, CA 95695, and I am looking for the nearest McDonald's location to feed my Big Mac Attack (do people still have those?).

I go to McDonalds.com and type my zip code into their location search. I get the following results listed in order from closest to furthest:

  1. 55 West Court St. Woodland, CA 95695 – 5.09 miles
  2. 1500 E Main St. Woodland, CA 95695 – 7.02 miles
  3. 1716 E Main St. Woodland, CA 95776 – 7.53 miles

If you search directions from my exact address to these exact addresses in Google Maps, you get the following results listed in order from closest to furthest:

  1. 1500 E Main St. Woodland, CA 95695 – .8 miles
  2. 55 West Court St. Woodland, CA 95695 – 1 mile
  3. 1716 E Main St. Woodland, CA 95776 – 1.4 miles

As you can see, the distance discrepancies here are not entirely unreasonable for a slimy burger fix, but they are far from accurate. The biggest problem with these results is that the McDonald's website says that the 55 West Court St. location is closer to me, when in reality, the 1500 E Main St. location is closer.

This is the discrepancy that didn't play nicely with how the client envisioned the feature. They simply wanted every result to be accurate for every person. The real challenge of implementing this feature isn't trying to finesse the logic of the code to produce the results you want, rather it's explaining the ins and outs of user interaction and expectations with your client. This is an art form I enjoy discussing to no end with people in my field. Trying to bring the laymen up to speed with the various nuances of such a vague topic is another story.

The client sees this as an exciting feature for their site, and therefore wants to include every possible bell and whistle, like maps, mileage and directions.

In reality, the client has 10 locations in a relatively small region of Northern California. Most visitors to their site who will use this feature are going to be quite familiar with the region and aren't going to care about precise mileage or a map with driving directions. A single list of all locations would be the most efficient, usable, and cost effective solution.

I'm hoping a compromise of approximating the order of the results without listing the mileage will be acceptable.

As a long time resident of Woodland, CA, I already know we have a few McDonald’s restaurants to choose from. I was just wondering if that one in the Wal*Mart was still open.